[Problem]
const { currentChannel, messages } = useGroupChannelContext()
// send a chatbot message via API and observe
console.log(currentChannel?.lastMessage)
console.log(messages.at(-1))
I’m implementing custom InputWrapper and noticed that:
- When sending a regular user message,
currentChannel.lastMessage
andmessages.at(-1)
are the same. - But when sending a bot message with the API, the
lastMessage
still shows the user message whilemessages.at(-1)
indeed is the bot’s message.
Here is the log
currentChannel?.lastMessage?.messageId 8317010301
messages.length 30
messages.at(-1).messageId 8317010301
// sent chatbot message, component got re-rendered
currentChannel?.lastMessage?.messageId 8317010301
messages.length 31
messages.at(-1).messageId 8317010417
[SDK Version]
3.14.14
[Reproduction Steps]
- Send a chatbot (not AI) message to a channel, observe that currentChannel.lastMessage doesn’t change
// CustomGroupChannel.tsx
<GroupChannel
renderMessageInput={() => (
<CustomMessageInput />
)}
/>
)
// CustomMessageInput.tsx
export function CustomMessageInput() {
const { currentChannel, messages } = useGroupChannelContext()
console.log(
'currentChannel?.lastMessage?.messageId',
currentChannel?.lastMessage?.messageId
)
console.log('messages.length', messages.length)
console.log('messages.at(-1).messageId', messages.at(-1).messageId)
return (<MessageInputWrapper/>)
}
[Frequency]
every time
[Current impact]
we can’t rely on lastMessage