Download PDF

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.

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 required 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()
Example :-
ticket.getCustomFields().get("d814-59414465-cf-3");
this would give the value of the custom field of with the ID d814-59414465-cf-3 for the current ticket.

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()
Example :-
ticket.getCustomerInfo().get("name");
this would give the value of the name field of the customer attached to ticket, where name is a table definition column

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 Variable

Use 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 Script

Use the following code to access a variable in the script.

variables.get("<variable_name>");

Following is an example.

variables.get("$agent");

Steps to apply HTTP Action

Select "HTTP Action" in the top drop-down menu of "Actions" section.

HTTP Action

Figure: HTTP Action

Now, perform the following steps.

  1. GET: Select it to retrieve the information that is identified by the API. After selecting, the interface shows the following elements.
    1. URL: Provide the URL of external API.
    2. Headers: Provide the key and its value. You can provide mutliple keys here.

      GET Method of HTTP Action

      Figure: GET Method of HTTP Action

    3. Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
    4. Post-Request Script: Provide the JavaScript code that will run after the execution of API.
  2. 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.

    1. 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.
    2. 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
    3. 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);
      

      POST Method of HTTP Action

      Figure: POST Method of HTTP Action

    4. 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);
      
      Here, the API token has to be provided in the database so that the system can authenticate it.
    5. 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
      }
      
  3. PUT: Select it to create or replace any resource that is provided by the API. After selecting, the interface shows the following elements.
    1. URL: Provide the URL of external API.
    2. Body: Provide the code to initialize and and access the variable.
    3. Headers: Provide the key and its value. You can provide mutliple keys here.

      PUT Method of HTTP Action

      Figure: PUT Method of HTTP Action

    4. Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
    5. Post-Request Script: Provide the JavaScript code that will run after the execution of API.
  4. DELETE: Select it to delete any resource that is requested by the API. After selecting, the interface shows the following elements.
    1. URL: Provide the URL of external API.
    2. Body: Provide the code to initialize and and access the variable.
    3. Headers: Provide the key and its value. You can provide mutliple keys here.

      DELETE Method of HTTP Action

      Figure: DELETE Method of HTTP Action

    4. Pre-Request Script: Provide the JavaScript code that will run before the execution of API.
    5. Post-Request Script: Provide the JavaScript code that will run after the execution of API.
    After selecting a method, you have to provide the inputs.

You can follow the same steps to add more HTTP Actions.
With HTTP Actions, you can add other actions also in Routing Rules, Event-based Rules, and Timer-based Rules. Click the following links to know more about the same.