FredrikOseberg / react-chatbot-kit

MIT License
301 stars 141 forks source link

When someone click on a button i want to display The text in the button as a client message . #5

Closed 88hichem88 closed 3 years ago

88hichem88 commented 3 years ago

In the action provider Please add a new function similar to this.createChatBotMessage("");

That allow to create a client message

this.createClientMessage("");

To display the text in the button clicked on So the client feel like he said something ( when he clicked on the button )

FredrikOseberg commented 3 years ago

I'll look into it. Meanwhile, you can create this method yourself. You just need to add a message to the messages array with the type "user".

In the actionprovider:

createClientMesssage = (message) => {
       const clientMessage = {
              message: message,
              type: "user", 
              id: somethingUnique
      }

     return clientMessage
}

setClientMessage = (message) => {
      this.setState(prevState => ({
           ...prevState, messages: [...prevState.messages, clientMessage]
      }))
}

Then:

// inside function
const clientMessage = this.createClientMessage("I'm looking for this item")
this.setClientMessage(message)
88hichem88 commented 3 years ago

Thanks a lot. I'm already developing my first bot with the chat-bot-kit and so far it's amazing. Wish you great success.