Skip to content

Commit

Permalink
Merge pull request #446 from l3vels/fix/voice-on-chat
Browse files Browse the repository at this point in the history
fix: voice on chat
  • Loading branch information
Chkhikvadze committed Feb 29, 2024
2 parents 0cd1d9f + 055c4b7 commit d43f6a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/server/agents/conversational/conversational.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ async def run(

yield res

history.create_ai_message(
ai_message = history.create_ai_message(
res,
human_message_id,
agent_with_configs.agent.id,
voice_url,
)

chat_pubsub_service.send_chat_message(chat_message=ai_message)
1 change: 1 addition & 0 deletions apps/ui/src/modals/AIChatModal/hooks/useChatSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const useChatSocket = ({ userId, createdChatId }: ChatSocketProps) => {
}
if (data.type === 'CHAT_MESSAGE_ADDED') {
upsertChatMessageInCache(data.chat_message, {
replaceCache: data.chat_message.message.data.type === 'ai' ? true : false,
agentId: data.agent_id,
teamId: data.team_id,
chatId: data.chat_id,
Expand Down
10 changes: 9 additions & 1 deletion apps/ui/src/modals/AIChatModal/hooks/useUpdateChatCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ const useUpdateChatCache = () => {

const upsertChatMessageInCache = (
newChatMessage: Record<string, unknown>,

{
localChatMessageRefId,
agentId,
teamId,
chatId,
replaceCache,
}: {
localChatMessageRefId?: Nullable<string>
agentId?: Nullable<string>
teamId?: Nullable<string>
chatId?: Nullable<string>
replaceCache?: boolean
} = {},
) => {
let queryVariables = omitBy(
Expand All @@ -45,7 +48,7 @@ const useUpdateChatCache = () => {
{ query: CHAT_MESSAGES_GQL, variables: queryVariables },
data => {
const chatMessages = data?.chatMessages || []
const newChatMessages = [...chatMessages]
let newChatMessages = [...chatMessages]
newChatMessage = {
__typename: 'ChatMessage',
parent: null,
Expand All @@ -54,6 +57,11 @@ const useUpdateChatCache = () => {
...newChatMessage,
}

if (replaceCache) {
const lastItemId = newChatMessages[newChatMessages.length - 1].id
newChatMessages = newChatMessages.filter((message: any) => message.id !== lastItemId)
}

if (localChatMessageRefId && user.id === newChatMessage.sender_user_id) {
// If the message is from the current user, we need to update the local message

Expand Down

0 comments on commit d43f6a9

Please sign in to comment.