Active WhatsApp Messages in Blip Desk: Return to a Bot Flow Block November 25, 2024 13:29 Updated Index: How to direct the return of the active message? Return to a Bot Flow block based on the attendant's status. How to direct the return of the active message? It is possible to direct the return of the active message to any block in the bot flow, whether it is new or existing. Making the customer go through the bot flow or part of it after the individual trigger performed within Blip Desk. In this case, it is important to note that, depending on the user's action, if there is an overflow, this action will always consider the rules defined in "Service Rules". Firstly, it is necessary to configure the Return Flow through the portal. Access the "Customer Service" page of your chatbot. In the side menu, click on "Message Templates". Then, choose the template you want to configure and click on the pencil icon on the right side of the screen. Select a block from the bot flow to which the customer's return will be directed. It is not possible to select more than one Return Flow for the same template. Important! Although it is possible to direct the return of the active message to an existing block in the bot flow, we suggest creating a new block to handle customizations related to active messages, as described below. When directing the customers return to a block in the bot flow that is not the human service block, the customer will be considered a bot contact. That is, it will no longer be a contact initiated by an Active Message in Blip Desk. Thinking about management and report creation, if it is necessary to track this return as a contact derived from an Active Message, it is necessary to perform the following configuration: 1. Click on “+Add exit action.” 2. A menu will open. Choose the option “Set variable.” 3. In the “Variable name” field, add the text: campaignId 4. In the “Value” field, add the text: {{contact.extras.campaignId}} 5. It is not necessary to fill in the “Expiration (optional)” field. 6. Click on the arrow next to “Set variables” to return to the initial view. Return to a block in the Bot Flow based on the agent's status In addition to directing the return of the active message to any block in the bot flow, it is possible to configure different actions based on the agent's status. To do this, access the "Builder" page and click on the selected block as the Return Flow (the same block defined in the previous step). On the right side of the screen, click on the Actions tab. Next, some customizations will be necessary, they are: Step 1 - Retrieving the Campaign ID: 1. In Input Actions, click on +Add input action. 2. A menu will open. Choose the option "Set variable." 3. In the Variable name field, add the text: campaignId 4. In the Value field, add the text: {{contact.extras.campaignId}} 5. In the Expiration (optional)* field, add the number: 60 6. Click on the arrow next to "Set variables" to return to the initial view. Important: Filling in this field is optional, but we suggest filling it in as indicated above so that the context variable does not become infinite. Step 2 - Retrieve the campaign by campaign ID: 7. Click again on +Add input action. 8. In the menu that opens, click on Process command. 9. In the To field, add the text: postmaster@activecampaign.msging.net 10. In the Method field, select the option: get 11. In the URI field, add the text: /campaigns/{{context.campaignId}} 12. In Save Response, in the Response Variable field, add the text: campaign 13. Click the arrow next to Process Command to return to the initial view. Step 3 - Extract the agent who triggered the event: 14. Click again on +Add input action. 15. A menu will open. Click on Run Script. 16. Click on Input Variables and add the variable: campaign 17. Next, click on Script and on the left side of the screen, paste the text below: function run(campaign) { var response = JSON.parse(campaign); var campaignExists = (response && response.resource) if (campaignExists) { var identity = response.resource.campaignSender; return (identity !== undefined) ? encodeURIComponent(identity) : identity; }} 18. On the right side of the screen, in Save Return, in the Variable for Return Value field, add the text: encodedAttendanceRedirect 19. Click the arrow next to Run Script to return to the initial view. Step 4 - Get the status of the agent who triggered the event: 20. In Output Actions, click on +Add Output Action. 21. In the menu that opens, click on Process command. 22. In the field For, add the text: postmaster@desk.msging.net 23. In the Method field, select the option: get 24. In the URI field, add the text: /agents/status?ownerIdentity={{context.encodedAttendanceRedirect}} 25. In Save Response, in the Response Variable, add the text: agentStatus 26. Next, in Condition to Process Command, click +Add Processing Condition. 27. In the If field, select the option: Variable 28. In the Condition field, select the option: Exists 29. In the Variable Name field, select the option: encodedAttendanceRedirect 30. Click the arrow next to Process Command to return to the initial view. Step 5 - Set the status of the attendant to a variable: 31. Click again on +Add Output Action. 32. A menu will open. Click on Run Script. 33. Click on Input Variables and add the variable: agentStatus 34. Next, click on Script and on the left side of the screen, paste the text below: function run(agentStatus) { var response = JSON.parse(agentStatus); var statusExists = (response && response.resource) if (statusExists) { return response.resource.status; }} 35. On the right side of the screen, under Save return, in the field Variable for the return value, add the text: status 36. Next, under Condition to execute script, click on +Add execution condition. 37. In the If field, select the option: Variable 38. In the Condition field, select the option: Exists 39. In the Variable Name field, select the option: agentStatus 40. Click the arrow next to Run Script to return to the initial view. Step 6 - Extract the agent who triggered the action: 41. Click again on +Add entry action. 42. A menu will open. Click on Execute script. 43. Click on Input variables and add the variable: campaign 44. Then, click on Script and on the left side of the screen, paste the text below: function run(campaign) { var response = JSON.parse(campaign); var campaignExists = (response && response.resource); if (campaignExists) { var identity = response.resource.campaignSender; return identity !== undefined ? identity : undefined; }} 45. On the right side of the screen, under Save return, in the Return value variable field, add the text: campaignSender 46. Click the arrow next to Execute script to return to the initial view. 47. In the If field, select the option: Variable 48. In the Condition field, select the option: Equals 49. In the Variable Name field, add the text: status 50. In the Value field, add the text: online 51. Click on the arrow next to "Set variables" to return to the initial view. Important: Filling out this field is optional, but we suggest filling it out as indicated above to prevent the context variable from becoming infinite. Step 7 - Set specific queue on overflow if the agent is not online: 52. Click again on +Add Output Action. 53. A menu will open. Choose the option "Set variable." 54. In the Variable Name field, add the text: attendanceQueueToRedirect 55. In the Value field, add the name of the queue to which the ticket will be redirected. 56. In the Expiration (optional)* field, add the number: 60 57. Next, in the Condition for setting variable field, click on +Add set variable condition. 58. In the If field, select the option: Variable 59. In the Condition field, choose the option: Not equal to 60. In the Variable Name field, add the text: status 61. In the Value field, add the text: online 62. Click on the arrow next to "Set variables" to return to the initial view. Important: Filling out this field is optional, but we recommend filling it out as indicated above to prevent the context variable from becoming infinite. Step 8 - Setting the campaign ID in the ticket: Important! When directing the customers response to a block in the bot flow other than the human service block, the customer will be considered a bot contact. Meaning they will no longer be a contact initiated by Active Message in Blip Desk. Thinking about management and report creation, if it is necessary to track this response as a contact derived from an Active Message, this step must be performed. 63. Click again on +Add Output Action. 64. A menu will open. Choose the option "Set variable." 65. In the Variable name field, add the text: campaignId 66. In the Value field, add the text: {{contact.extras.campaignId}} 67. In the Expiration (optional)* field, add the number: 60 68. Click on the arrow next to "Set variables" to return to the initial view. Important: Filling out this field is optional, but we suggest filling it out as indicated above to prevent the context variable from becoming infinite. For more information, visit the discussion on the subject in our community or the videos on our channel. 😃 Related articles Sending WhatsApp Active Messages on Blip Desk How to configure an active message response redirecting for an attendant in Blip Desk How to send WhatsApp notifications through Blip API How to Send Notifications via the Active Campaign API (Growth) Active Messages - Error Codes