How can i pass customer data(gender,fullname...) to Bot?

I want to send some customer data : gender, email, fullname, phonenumber… to bot when chat init.
I don’t know how to do this? can anyone suggest solution for me?
thank you

Botpress does not allow any custom parameter to be passed in chat init. You can pass only userId which should be uniquely identifiable.

There are 2 ways you can get and use custom parameters in your bot.

  1. Use sendEvent to pass payload as soon as the chatbot window is opened. An example is given below.
        window.botpressWebChat.sendEvent({
          type: 'proactive-trigger',
          channel: 'web',
          payload: { text: 'Hey' }
        })
  1. Use a custom action in before incoming middleware to call you API which returns relevant information for a given userId.

Also, check out my blog given below for more Botpress tutorials.

To complement @abhisheksimion’s answer, I would suggest a mix of both.

  1. Create a custom payload with the user
  // In the page where the webchat is embedded
  window.addEventListener('message', function(event) {
     // When the webchat is loaded, sends this payload to the backend
      if (event.data.name === 'webchatLoaded') {
        window.botpressWebChat.sendEvent({
          type: 'update-profile',
          payload: {
            firstname: 'first',
            lastname: 'name',
            gender: '...'
          }
        })
      }
    })
  1. Add a before_incoming_middleware to catch that event and update the profile

3 Likes