User Closing Tickets July 12, 2023 20:47 Updated Index: Exit condition Action to close the ticket Close the ticket of customers using the MS Teams channel Currently, there are two native ways to close tickets: through the attendant using Blip Desk or through attendant or user inactivity. If you wish to offer the option for your customer to choose to close a ticket, the following configurations must be made in your human support bot: Exit condition An exit condition must be added in the human assistance block, for example, it can exit the block when the user types “Exit”. However, when exiting the block, the ticket remains open and it will be necessary to close it manually. Action to close the ticket To close the ticket, in the block to which the user will be directed, add an input action of Process command with the command to close a ticket with the following request: https://docs.blip.ai/#close-a-ticket-as-user (If the option “Use router context” is enabled, it will be necessary to replace the actions “Process command” with HTTP Requests, step by step at the end of the article.) To get the ticket id just send the following command: For: postmaster@desk.msging.net Method: get URL: /tickets?$filter=(status%20eq%20'open'%20or%20status%20eq%20'waiting')%20and%20(CustomerIdentity%20eq%20'{{contact.identity}}')&$skip=0&$take=100 Here's an example: To filter the desired ticket, create a Run Script action: Add the ticket input variable that will have the ticket number that was found in the Process Command action executed before the Run Script action. Then enter the following script: function run(ticket) { try { let ticket = JSON.parse(ticket); return ticket.resource.items[0].id; } catch (error) { return 'script error'; } } Add a variable to save the return, for example: ticketId. Here's an example: After the run script action, add one more action of type Process command to close the ticket: For: postmaster@desk.msging.net Method: set URL: /tickets/change-status Type: application/vnd.iris.ticket+json Resource: {"id":"{{ticketId}}","status":"ClosedClient"} Save response: responseClose The input actions of the block to which the user will be directed when typing “exit”, for example, will be in the following order: If you use a router structure and the Use router context option is enabled, you will need to use HTTP Request actions instead of “Process command” actions. The first request must contain the following parameters: Method: PostNote: Use the url with the contract id to consume the endpoints informed below, your performance and functioning can be impacted if you do not have the contract id, therefore, it is essential use the url with the id of the contract to use http requests! URL: https://{{contractid}}.http.msging.net/commands Headers: Content-Type: application/json Authorization: API KEY do seu bot Body: {"id": "{{random.guid}}","to": "postmaster@desk.msging.net","method": "get","uri": "/tickets?$filter=(status%20eq%20'open'%20or%20status%20eq%20'waiting')%20and%20(CustomerIdentity%20eq%20'{{contact.identity}}')&$skip=0&$take=100"} Save the answers in variables. It will look like this: The second request will override the process command action to finalize the ticket. Method: PostNote: Use the url with the contract id to consume the endpoints informed below, your performance and functioning can be impacted if you do not have the contract id, therefore, it is essential use the url with the id of the contract to use http requests! URL: https://{{contractid}}.http.msging.net/commands Headers: Content-Type: application/json Authorization: API KEY do seu bot Body: { "id": "{{$guid}}", "to": "postmaster@desk.msging.net", "method": "set", "uri": "/tickets/change-status", "type": "application/vnd.iris.ticket+json", "resource": { "id": "{{ticketId}}", "status": "ClosedClient" }} Save the answers in variables. Finally, in the block where the actions to finalize the ticket will be executed, define an exit condition for the user who finalized the ticket: Close the ticket of customers using the MS Teams channel To close the ticket for customers using the MS Teams channel, in the block to which the user will be directed, add an input action of Process command with the command to close a ticket with the following request: https://docs.blip.ai/#close-a-ticket-as-user (If the option “Use router context” is enabled, it will be necessary to replace the actions “Process command” with HTTP Requests, step by step at the end of the article.) Step 1: To search for all tickets that are open or on hold, we use the command: For: postmaster@desk.msging.net Method: get URL: /tickets?$filter=status%20eq%20'open'%20or%20status%20eq%20'waiting'&$skip=0&$take=100 Here's an example: Step 2:To filter the desired ticket, create a Run Script action: Add the ticket input variable that will have the ticket number that was found in the Process Command action executed before the Run Script action. The body of the script will look like this: function run(ticketvar) { var jsonVar = JSON.parse(ticketvar); jsonVar.resource.items.forEach(item => { if (item.customerIdentity == "{{contact.identity}}") { jsonVar.resource.items = []; jsonVar.resource.items.push(item); } }); return jsonVar.resource.items[0].id; }; Obs.: Lembrar de após escrever o script apertar CTRL+S para salvar. Step 3: After the run script action, add one more action of type Process command to close the ticket: For: postmaster@desk.msging.net Method: set URL: /tickets/change-status Type: application/vnd.iris.ticket+json Resource: {"id":"{{ticketId}}","status":"ClosedClient"} Save answer: responseClose The input actions of the block to which the user will be directed when typing “exit”, for example, will be in the following order: For more information, visit the discussion on the subject in our community or the videos on our channel. 😊 Related articles How to close tickets Setting up Session Expiration and Timeout How to Send SMS via API Sending WhatsApp Active Messages on Blip Desk Sending Data for Analysis via Webhooks