MessagingService Plugin - Start Web Messaging

I am trying to configure toast pop up notification, similar to what is described here: Once agent finishes web message, send to a bot flow

I am able to deploy the toast notification without any problems but I am struggling to re-initiate the message session. I want to be able to re-initialise the web message chat after the agent disconnects so I can send the customer back into the flow to complete a survey.

I've been looking at the following article but can't figure out the right combination of commands to re-initialise: https://developer.genesys.cloud/commdigital/digital/webmessaging/messengersdk/SDKCommandsEvents/messagingServicePlugin#messagingservice-sendmessage

I can re-initiate session by using "MessagingService.sendMessage" or "MessagingService.resetConversation" but is this the correct way to do this?

I've tried a lot of the other commands but they don't appear to start the conversation again. Instead the customer is presented with option to "Start new" button.

Here is the example of my code:

(function (g, e, n, es, ys) {
    g['_genesysJs'] = e;
    g[e] = g[e] || function () {
      (g[e].q = g[e].q || []).push(arguments)
    };
    g[e].t = 1 * new Date();
    g[e].c = es;
    ys = document.createElement('script'); ys.async = 1; ys.src = n; ys.charset = 'utf-8'; document.head.appendChild(ys);
  })(window, 'Genesys', 'https://apps.mypurecloud.ie/genesys-bootstrap/genesys.min.js', {
    environment: 'euw1',
    deploymentId: 'XXXXXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
  });

Genesys("subscribe", "MessagingService.conversationDisconnected", function({data}){
    console.log(data);
	Genesys("command", "Database.get", { name: "messaging.customAttributes.surveyOptIn" },
		function(data){
			console.log("Survey Offered Already");
		},
		function(){
			Genesys("subscribe", "Toaster.ready", () => {
                Genesys("command","Toaster.open",
                        {
							title: "Would you like to take part in a survey?",
							body: "In order to improve our services we'd like to ask you a quick 5 question survey.",
							buttons: {
								type: "binary", // required when 'buttons' is present. Values: "unary" for one action button, "binary" for two action buttons
								primary: "Yes", // optional, default value is "Accept"
								secondary: "No", // optional, default value is "Decline"
							},
						},
                        function () {
							/*fulfilled callback*/
							console.log("Toaster is opened");

						},
								function (error) {
							/*rejected callback*/
							console.log("There was an error running the Toaster.open command:", error);
						}
                );
            });
		}
	);
});

Genesys("subscribe","Toaster.accepted",
	function (e) {
		console.log("Toaster was accepted", e);
		Genesys("command", "Database.set", { messaging: { customAttributes: { surveyOptIn: 'true' }}},
              function(data){ /* fulfilled, returns data */}, function(){ /* rejected */ });
		// Re-initiate the conversation at this point? What commend is required?
		Genesys("command", "Messenger.openConversation");
	}
);

Genesys("subscribe","Toaster.declined",
	function (e) {
		console.log("Toaster was declined", e);
	}
);

Thanks,
Darren

Hi Darren,

Do you have your messenger configured to not end when the agent disconnects?

From Configure Messenger - Genesys Cloud Resource Center :

In Admin > Messenger Configuration
image

Remember to update deployment with new configuration version!

EDIT:
Unless you don't wan the conversation to continue, in which case you need to start a new conversation for the survey. If you try to just start a new one, the console error will show there is still a conversation configured, so you need to first do resetConversation which will also start a new conversation, which you can then do the sendMessage on.

Hi, Anton,

Thanks I had setting "Display Conversation Status" enabled initially I then switched to "Display conversation status and disconnect session".

I tried "Do no display conversation status" but then I do not get a "MessagingService.conversationDisconnected" event when the agent disconnects.

Maybe there is another event I need to subscribe to instead.

Ideally I want to retain the survey conversation in the same conversation as original interaction if that is possible.

Thanks,
Darren

Hi Darren

If you stick with the disconnect interaction path, you could use resetConversation as mentioned in my edit.
But yes new conversation.

Here is the conundrum, you want the conversation to continue and not end, but I think (and could be wrong) you don't get a disconnect event without the conversation ending, so there is no event to trigger the survey.

Open Messaging might be easier for this, but yes huge amount of effort to set up.
We've certainly come across the web messenger limitation for a number of things, and the suggestion has always been go Open Messaging.

Some other options to consider,
Send an email with a survey link.
Provide a web UI element for customers as soon as the conversation starts that allows them to complete a survey at any point not just at the end,

Thanks for the input, for now I will use the "MessagingService.sendMessage" to trigger the survey. Not perfect but will do and saves me using open messaging.

Genesys("command", "MessagingService.sendMessage", {
    message: "Survey: Yes"
},
    function() {
        /*fulfilled callback*/
    },
    function() {
        /*rejected callback*/
    }
);

Thanks,
Darren

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.