-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add avatars to bot and user messages (#867)
* add avatars to bot and user messages * set default avatar for user and chatbot and fix a bug
- Loading branch information
Showing
10 changed files
with
152 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div id="config-bot-avatar-url">{bot_avatar}</div> | ||
<div id="config-user-avatar-url">{user_avatar}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
function addAvatars(messageElement, role='user'||'bot') { | ||
if (messageElement.classList.contains('avatar-added') || messageElement.classList.contains('hide')) { | ||
return; | ||
} | ||
if (role === 'bot' && botAvatarUrl === "" || role === 'user' && userAvatarUrl === "") { | ||
messageElement.classList.add('avatar-added'); | ||
return; | ||
} | ||
|
||
|
||
const messageRow = document.createElement('div'); | ||
messageRow.classList.add('message-row'); | ||
messageElement.classList.add('avatar-added'); | ||
|
||
if (role === 'bot') { | ||
messageRow.classList.add('bot-message-row'); | ||
} else if (role === 'user') { | ||
messageRow.classList.add('user-message-row'); | ||
} | ||
|
||
const avatarDiv = document.createElement('div'); | ||
avatarDiv.classList.add('chatbot-avatar'); | ||
if (role === 'bot') { | ||
avatarDiv.classList.add('bot-avatar'); | ||
avatarDiv.innerHTML = `<img src="${botAvatarUrl}" alt="bot-avatar" />`; | ||
} else if (role === 'user') { | ||
avatarDiv.classList.add('user-avatar'); | ||
avatarDiv.innerHTML = `<img src="${userAvatarUrl}" alt="user-avatar" />`; | ||
} | ||
|
||
messageElement.parentNode.replaceChild(messageRow, messageElement); | ||
|
||
if (role === 'bot') { | ||
messageRow.appendChild(avatarDiv); | ||
messageRow.appendChild(messageElement); | ||
} else if (role === 'user') { | ||
messageRow.appendChild(messageElement); | ||
messageRow.appendChild(avatarDiv); | ||
} | ||
} | ||
|
||
function clearMessageRows() { | ||
const messageRows = chatbotWrap.querySelectorAll('.message-row'); | ||
messageRows.forEach((messageRow) => { | ||
messageRow.parentNode.removeChild(messageRow); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
.message-wrap>div img{ | ||
.md-message img{ | ||
border-radius: 10px !important; | ||
} | ||
|
||
|