Transfer a Conversation from One Engagement Adapter to Another

This tutorial demonstrates how to set up the capability to transfer a user’s conversation from one channel to another.

Prerequisites

Background

In some cases a user may start a conversation with your bot on one channel, but it may be preferable to transfer to user to another channel. For example, a user starts a conversation with your bot on Facebook Messenger, but based on the flow of conversation they are transferred to an FAQ’s page on your website where they can continue the conversation there.

There is a transferConversation Classic Flow node that can be used to facilitate the conversation transfer.

Transfer Conversation Flow

The general flow for transferring a conversation is as follows:

  • The trasferConversation node generates a one time use token that can be used to re-instantiate the existing conversation on a webpage of your choice.
  • Your bot returns a URL to the user to visit the webpage. The URL contains the token value as a URL parameter, e.g. https://mywebsite.com?sbReference=$tokenValue
  • The token can be passed into window.ServisBot.init() to re-instantiate the conversation on the webpage.

Using the Transfer Conversation Node

The transferConversation node generates a secure, one time token that can be used to re-instantiate the conversation on a new webpage. The example template below can get you started.

[{"id":"bc124f15.58017","type":"start","z":"490de6ab.1f5d38","name":"Start","x":70,"y":160,"wires":[["2303768a.e5348a"]]},{"id":"be691efc.1eacf","type":"comment","z":"490de6ab.1f5d38","name":"Start nodes trigger when conversations are created","info":"This will be triggered only when a new user is introduced to the bot\n\nUse an ActionStart if this flow is triggered from a botnet action","x":210,"y":80,"wires":[]},{"id":"7b820ef4.773a","type":"transferConversation","z":"490de6ab.1f5d38","name":"","x":800,"y":120,"wires":[["2a9f6650.9a3a3a"],["b65f1ee7.b278e"]]},{"id":"b65f1ee7.b278e","type":"dialogue","z":"490de6ab.1f5d38","name":"","message":"Hello, how can I help today?","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":280,"y":160,"wires":[["bb2212ee.43a66"]]},{"id":"bb2212ee.43a66","type":"input","z":"490de6ab.1f5d38","name":"","x":450,"y":120,"wires":[["f7bebd78.cfc01"]]},{"id":"2a9f6650.9a3a3a","type":"setContext","z":"490de6ab.1f5d38","name":"","contextsToSet":[{"value":"transferConversationToken","key":"transferTokenValue","valueType":"msg"}],"x":1070,"y":120,"wires":[["2b5c36f1.811daa"]]},{"id":"799545d0.d75dfc","type":"dialogue","z":"490de6ab.1f5d38","name":"","message":"Please follow the link: https://messenger.servisbot.com/v2/preview.html?organization=example-organization&endpoint=my-endpoint&sbRegion=eu-1&sbReference=$transferTokenValue","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":1600,"y":120,"wires":[["b65f1ee7.b278e"]]},{"id":"2b5c36f1.811daa","type":"change","z":"490de6ab.1f5d38","name":"","rules":[{"p":"payload.user.transferTokenValue","tot":"msg","to":"payload.context.transferTokenValue","t":"set","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":120,"wires":[["799545d0.d75dfc"]]},{"id":"2303768a.e5348a","type":"input","z":"490de6ab.1f5d38","name":"","x":190,"y":220,"wires":[["b65f1ee7.b278e"]]},{"id":"f7bebd78.cfc01","type":"dialogue","z":"490de6ab.1f5d38","name":"","message":"For help please go to our website","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":600,"y":120,"wires":[["7b820ef4.773a"]]}]

Import this flow into your designer and you should see the following flow.

Transfer Conversation Flow

The transferConversation node generates the token which will be available on msg.transferConversationToken. Building the URL that includes the token happens separately. In this flow, the following steps take place:

  • The setContext node is used to set msg.payload.context.transferTokenValue to be equal to msg.transferConversationToken.
  • The change node is used to move the value from msg.payload.context.transferTokenValue to msg.payload.user.transferTokenValue, which makes transferTokenValue easy to reference in a dialogue node.
  • Lastly, the dialogue node is used to build a URL to return to the user.

In this example, the URL being generated is as follows:

https://messenger.servisbot.com/v2/preview.html?organization=example-organization&endpoint=my-endpoint&sbRegion=eu-1&sbReference=$transferTokenValue

This URL is pointing to the bot testing page in the ServisBot platform, but you could replace it with your own webpage where the servisbot messenger is embedded, e.g.

https://mywebsite.com?sbReference=$transferTokenValue

Re-instantiating the Conversation

On your webpage you can use JavaScript to get the sbReference value and pass it into window.ServisBot.init().

const urlParams = new URLSearchParams(window.location.search);

const sbReference = urlParams.get('sbReference');

window.ServisBot.init({
    sbReference: sbReference,
    organization: 'your-organization',
    endpoint: 'your-endpoint',
    ...
})

The presence of the sbReference parameter will cause the conversation to be re-instantiated within the messenger component when it is loaded. The conversation history will be loaded and the user will be able to continue the conversation from where they left off.