botpress / v12

Botpress OSS – v12
https://v12.botpress.com
GNU Affero General Public License v3.0
71 stars 83 forks source link

Webchat configure does not update socket's userId #1076

Closed BPMJoannette closed 1 year ago

BPMJoannette commented 4 years ago

When calling botpressWebChat.configure with a new user ID, the conversation is not refreshed to show the new user's.

To Reproduce Steps to reproduce the behavior:

  1. In the embedded-webchat.html example page, add the following event listener:

    window.addEventListener("message", function (message) {
        if (message.data.text === "authorized") {
          window.botpressWebChat.configure({ userId: message.data.userId });
        }
      });
  2. In Botpress, create a before incoming middleware hook with this:

    if (event.payload.text !== 'change') {
    return
    }
    
    async function hook() {
    const authorized = bp.IO.Event({
      type: 'data',
      channel: event.channel,
      target: event.target,
      botId: event.botId,
      direction: 'outgoing',
      payload: {
        type: 'text',
        text: 'authorized',
        userId: 'changedId'
      }
    })
    bp.events.sendEvent(authorized)
    }
    return hook()
  3. Load the embedded-webchat example, send any first message to initiate conversation.

  4. Send "change" to trigger the hook. Note that under Control User Identity, you have been assigned a new userId

  5. Send a third message. It is not posted back, and you don't get an answer either.

In the database I find the message is posted to the new user, but the conversation ID is not updated either. Multiple users shouldn't be able to have the same conversation ID.

Expected behavior Botpress web chat is reinitialized / refreshed with the correct user and conversation

Screenshots image

Environment:

Additional context Customer related issue

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Uttam92477 commented 3 years ago

Facing the same issue.

EFF commented 2 years ago

@Uttam92477 Are you still facing this issue in the more recent versions of botpress ?

Uttam92477 commented 2 years ago

This issue needs a documentation update. It is indeed updating the userId however, we have to use mergeConfig instead of the normal config API.

EFF commented 2 years ago

Yes you're right when you want to change anything in the config after the initialization you need to use mergeConfig. It needs a doc update. Thanks, we'll make sure to fix this properly

kubica commented 2 years ago

I currently facing the same issue. Even when using mergeConfig in the examplary workflow described by @BPMJoannette, the value of bp/socket/user is not changed.

Is this behavior expected, when setting a custom userId?