HTTP Action
You can select "HTTP Action" as an action while creating a rule for Media Profile in "Rule" tab of "System Configuration". HTTP Action also called Webhook triggers an external API to process those messages which meet the pre-selected conditions. Before going ahead to use this options, you should know about the common definitions, data that can be accessed, API response data, and variables. After introduction to these fields, the steps to apply HTTP Action will be discussed.
Common Definitions
Following common attributes are used in all methods of HTTP Action in "Rules" tab.
- URL: Provide the URL of the API that has to be triggered.
- Body: It is of the following two types.
- Form-Data: Enter the body content of API in key and value format. Both have to be provided separately. You have to provide a key and then its value.
- Raw: Enter the body content in the raw (that is general code) format.
- Header: Provide the header of the API.
- Pre-Request Script: It should contain JavaScript Code that is executed before the API Request. It is used to create the variables that can be used in URL, Header, and Parameters.
- Post-Request Script: It should contain JavaScript code that is executed after the API Request. It is used to create the variables and consume the API response, which will trigger through the action.
Data that can be accessed in HTTP Action Scripts
As of now, only data related to "Tickets" can be accessed through the scripts provided in the HTTP Action. Please refer to the following table to know the data that can be accessed and the requied function to access it.
Table: Ticket Data and its Calling Methods
Data | Calling Methods for Script |
---|---|
ticket id |
ticket.getTicketId() |
hasUnreadMessage |
ticket.getHasUnreadMessage() |
process id |
ticket.getProcessId() |
contact center id |
ticket.getContactCenterId() |
campaign id |
ticket.getCampaignId() |
queue id |
ticket.getQueueId() |
assigned user id |
ticket.getAssignedUserId() |
attached customer id |
ticket.getCustomerId() |
ticket source type |
ticket.getSourceType() |
ticket source sub type |
ticket.getSourceSubType() |
escalation |
ticket.getIsEscalated() |
date created |
ticket.getDateAdded() |
last modified date |
ticket.getDateModified() |
list of merged ticket ids |
ticket.getMergedTicketList() |
reopen count |
ticket.getReopenCount() |
ticket subject |
ticket.getSubject() |
ticket priority |
ticket.getPriority() |
external state |
ticket.getExternalState() |
first response date |
ticket.getFirstResponseDate() |
first resolve date |
ticket.getResolveDate() |
first assigned date |
ticket.getFirstAssignedDate() |
ticket custom field data |
ticket.getCustomFields() |
count of outgoing messages |
ticket.getOutgoingMessageCount() |
count of incoming messages |
ticket.getIncomingMessageCount() |
count of outgoing calls |
ticket.getOutgoingCallCount() |
count of incoming calls |
ticket.getIncomingCallCount() |
if ticket has failure messages |
ticket.hasFailureMessage() |
heat value |
ticket.getHeatValue() |
count of outgoing chats |
ticket.getOutgoingChatCount() |
count of incoming chats |
ticket.getIncomingChatCount() |
last reopen date |
ticket.getLastReopenDate() |
last unassigned ate |
ticket.getLastUnassignedDate() |
ticket customer information |
ticket.getCustomerInfo() |
if first assign SLA is achieved |
ticket.getFirstAssignedSlaAchieved() |
if first response sla is achieved |
ticket.getFirstResponseSlaAchieved() |
if resolve sla is achieved |
ticket.getResolveSlaAchieved() |
time remaining for first assign sla |
ticket.getTimeRemainingToAchieveFirstAssignSlaInSeconds() |
time remaining for first response sla |
ticket.getTimeRemainingToAchieveFirstResponseSlaInSeconds() |
time remaining for resolve sla |
ticket.getTimeRemainingToAchieveResolveSlaInSeconds() |
if ticket is assigned or not |
ticket.getHasTicketAssigned() |
if a response is made on ticket or not |
ticket.getHasTicketResponded() |
if ticket has been resolved or not |
ticket.getHasTicketResolved() |
source of the ticket |
ticket.getSource(); |
Initial target of the ticket (same as target of message from which ticket was made) |
ticket.getInitialTarget(); |
API Response Data that can be accessed in Post Request Script
Following API Response Data can be in the Post Request Script.
Data |
Method to access the Data |
---|---|
Response Code Received |
responseCode |
Response String Received |
responseString |
Initialization and Accessing Variable in Scripts
Initialize a VariableUse the following code to initialize a variable in the script.
variables.put("<variable_name>","<variable_value>");
Following is an example.
variables.put("$agent","mary");
Access a Variable in ScriptUse the following code to access a variable in the script.
variables.get("<variable_name>");
Following is an example.
variables.get("$agent");
- Variables that are to be used for replacement in url, headers and parameters must start with initial $. Else replacement would not work.
- Once a variable is initialized, that variable can accessed throughout the execution of the rule. That is once a variable is initialized in an HTTP ACTION, it can be accessed in another HTTP ACTION configured after it.
- If a variable with same name is initialized when a variable with same name exists, the value of the variable is replaced.
Steps to apply HTTP Action
Select "HTTP Action" in the top drop-down menu of "Actions" section.
Figure: HTTP Action
Now, perform the following steps.
- GET: Select it to retrieve the information that is identified by the API. After selecting, the interface shows the following elements.
- URL: Provide the URL of external API.
- Headers: Provide the key and its value. You can provide mutliple keys here.
Figure: GET Method of HTTP Action
- Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
- Post-Request Script: Provide the JavaScript code that will run after the execution of API.
- POST: Select it to send data to the server that is provided by the API. After selecting, the interface shows the following elements.
Here, the sample code for an API will be provided in the examples of the elements.
- URL: Provide the URL of external API. Following is a sample URL.
<protocol>://<domain_name>:<port>/ameyorestapi/tickets/$ticketId/notes
Replace "protocol" with http or https, "domain_name" with the domain name or IP Address of the location where Ameyo Server is installed, and "port" with the port number such as 8888 for HTTP and 8443 for HTTPS. - Headers: Provide the key and its value. You can provide mutliple keys here.
For an example, we are providing following headers in key and value format.
Authorization : $token
Content-Type : application/json - Body: Provide the code to initialize and and access the variable.
In this example, we are providing the code in raw format in "Body" to initialize the variable from response.var response=responseString; eval(\"response = \" +response + \";\"); variables.put("$noteId",response.noteId);
Figure: POST Method of HTTP Action
- Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
Following is a sample code.
variables.put("$token","fecace70bff6ea0c"); // this is the same token we configured in database variables.put("$ticketId",ticket.getTicketId()); variables.put("$ticketId",ticket.getAssignedUserId()); var subject= ' note for testing http action for '+ ticket.getTicketId(); variables.put("$subjectForNote",subject);
- Post-Request Script: Provide the JavaScript code that will run after the execution of API.
Following is an already known API Response of a sample POST Method.{ "noteId": "d414-5a6c16fc-MessageId-2", "subject": "regarding ticket resolution", "description": "this is test description", "messageType": "EXTERNAL_NOTE", "userId": "mary", "dateModified": 1517034536012, "dateAdded": 1517034536012 }
- URL: Provide the URL of external API. Following is a sample URL.
- PUT: Select it to create or replace any resource that is provided by the API. After selecting, the interface shows the following elements.
- URL: Provide the URL of external API.
- Body: Provide the code to initialize and and access the variable.
- Headers: Provide the key and its value. You can provide mutliple keys here.
Figure: PUT Method of HTTP Action
- Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
- Post-Request Script: Provide the JavaScript code that will run after the execution of API.
- DELETE: Select it to delete any resource that is requested by the API. After selecting, the interface shows the following elements.
- URL: Provide the URL of external API.
- Body: Provide the code to initialize and and access the variable.
- Headers: Provide the key and its value. You can provide mutliple keys here.
Figure: DELETE Method of HTTP Action
- Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
- Post-Request Script: Provide the JavaScript code that will run after the execution of API.
You can follow the same steps to add more HTTP Actions. With HTTP Actions, you can add "Set Priority" and "Routing" actions also.
Refer to "Steps to Add Actions" to know how to add these actions.