How to get a dated ticket by fluxo do bot May 02, 2023 13:23 Updated Index: Entry Actions Encode the contact identity Command to get the ticket Script to retrieve command response ticket Use variable From this tutorial, it will be possible to obtain the last dated ticket of the client from the flow of the bot, giving greater possibilities to the configuration of the flow. Entry Actions As a suggestion, in a block after the flow of the human service cashier, customize the entry modes to obtain the last customer ticket Encode the contact identity To make it possible to use the contact identity in the ticket filter from the url, it is necessary to add an Execute Script stage that has as Input Variable the contact.identity variable and Save Return in a variable such as helpDeskEncodedFromIdentity. Do not enter the Script, insert the following code: Script: function run(identity) { return (identity !== undefined) ? encodeURIComponent(identity) : identity;} Command to get the ticket To obtain the ticket, it is necessary to add a Process Command stage for the Desk, saving the response in a variable such as ticketsResponse and marking the use of the chatbot context. To: postmaster@desk.msging.net Method: get URI: /tickets?$filter=customerIdentity%20eq%20%27{{helpDeskEncodedFromIdentity}}%27%20and%20%28status%20eq%20%27ClosedClient%27%20or%20status%20eq%20%27ClosedAttendant%27%20or %20status%20eq%20%27ClosedClientInactivity%27%29&$skip=0&$take=1 Response Variable: ticketsResponse Also about the processing, to avoid errors, it is recommended to add a conditional for the execution of the command, as in the example below: Script to retrieve command response ticket After finishing obtaining the ticket, it will be necessary to treat the return to save in a variable only the required ticket. For isso, just add an Execute Script stage with the input variable ticketsResponse and Save Return in a variable like closedTicket. No body do Script add the following code: Script: function run(tickets) { var response = JSON.parse(tickets); var ticketExists = (response && response.resource && response.resource.items && response.resource.items.length > 0) if (ticketExists) { return response.resource.items[0]; }} Use variable Now the variable closedTicket can be used in various ways without flowing from the bot, as in the example below, where it is recovered, from the content, to the row of the last dated customer ticket. For more information, visit the discussion on the subject in our community or the videos on our channel. 😃 Related articles User Closing Tickets Automatic Closure due to Client Inactivity What is WhatsApp Flows? How to close tickets How to import a bot flow in Builder