react-chat-widget icon indicating copy to clipboard operation
react-chat-widget copied to clipboard

badge doesn't increment

Open mounabenayed opened this issue 5 years ago • 5 comments

I used the react-chat-widget to create a chatbot. When the bot replies to the user I want to increment the badge's value. I created a global var that increments when the bot answers and get back to zero when the user write his input. the I pass it to the badge as the following render() { return (<Widget badge={} handleNewUserMessage={this.handleNewUserMessage} profileAvatar={profileAvatar} subtitle="" title="Chatbot" /> ); but it seems not be working. So I am wondering how it does work and how can I resolve my issue

mounabenayed avatar May 10 '19 10:05 mounabenayed

You need to pass number in badge for example

badge='4'

here your working code

render() { return (<Widget badge=4 handleNewUserMessage={this.handleNewUserMessage} profileAvatar={profileAvatar} subtitle="" title="Chatbot" /> );

ashadnasim52 avatar Jun 05 '19 12:06 ashadnasim52

You need to count the messages on the addResponseMessage that updates your badge. Maybe push the messages into an array and get the length of the array and use that to update the badge.

snetts avatar Nov 29 '19 06:11 snetts

Can someone suggest a more clear approach towards this

kartikmaan avatar Jan 21 '20 13:01 kartikmaan

the standart addResponseMessage method set a number to badge count, when widget is in minimized state.

but, when use the renderCustomComponent method does not set a number for the badge count.

image

Bonfims avatar Sep 21 '20 14:09 Bonfims

I agree with @kartikmaan. This could use a more clear way to be done. Either exposing the current count so we can pass a new value to increment it, or a method to increment the value by a given number. Here is a way to get it working in the meantime:

image

This worked, but it just seems very hacky if its already being kept track of.

jawetzel avatar Nov 09 '20 20:11 jawetzel