Skip to content

Commit

Permalink
fix(messaging): show bot typing from buttons (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy authored Mar 5, 2024
1 parent 6f6a636 commit a47d33c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/webchat/src/components/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Message extends Component<MessageProps> {
isLastGroup: this.props.isLastGroup!,
isBotMessage: this.props.isBotMessage!,
sentOn: this.props.sentOn!,
onSendData: this.props.onSendData!,
onSendData: (payload) => this.props.onSendData!(payload, { showBotTyping: true }),
onFileUpload: this.props.onFileUpload!,
store: this.props.store,
onAudioEnded: this.props.onAudioEnded,
Expand Down
9 changes: 6 additions & 3 deletions packages/webchat/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ class RootStore {

this.composer.updateMessage('')
try {
this.isBotTyping.set(true)
const message = await this.sendData({ type: 'text', text: textMessage })
const message = await this.sendData({ type: 'text', text: textMessage }, { showBotTyping: true })
trackMessage('sent')
if (message) {
postMessageToParent('MESSAGE.SENT', message, this.config.chatId)
Expand Down Expand Up @@ -438,12 +437,16 @@ class RootStore {

/** Sends an event or a message, depending on how the backend manages those types */
@action.bound
async sendData(data: any): Promise<Message | void> {
async sendData(data: any, options?: { showBotTyping?: boolean }): Promise<Message | void> {
if (!this.isInitialized || !this.currentConversationId) {
console.warn('[webchat] Cannot send data until the webchat is ready')
return
}

if (options?.showBotTyping) {
this.isBotTyping.set(true)
}

const message = await this.api.sendMessage(data, this.currentConversationId)
this.updateLastMessage(this.currentConversationId, message)

Expand Down
2 changes: 1 addition & 1 deletion packages/webchat/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export namespace Renderer {
sentOn?: Date
inlineFeedback?: any

onSendData?: (data: any) => Promise<Message | void>
onSendData?: (data: any, options?: { showBotTyping?: boolean }) => Promise<Message | void>
onFileUpload?: (label: string, payload: any, file: File) => Promise<void>

/** Allows to autoplay voice messages coming from the bot */
Expand Down

0 comments on commit a47d33c

Please sign in to comment.