Script Choice Module - Script Testing

The Script Choice, or Evaluate JavaScript pipeline activity evaluates custom JavaScript, and can be inserted anywhere in a pipeline.

Session Metadata

All of a sessions metadata properties can be accessed through JavaScript using the following format: sessionMetaData.<Metadata Variable>.

Default session metadata properties represented in JSON can be seen below.

Examples of Accessing Metadata Properties

Get Guest question:

sessionMetaData.Guest.Question

Get Guest Name:

sessionMetaData.Guest.Name

Get Session ID:

sessionMetaData.Session.SessionId

Default Session Metadata Properties Represented as JSON

 "Guest": {
        "Name": "John Doe",
        "Id": "dl_vBFbdIv1Y0aPMOsabBBC9Q@30ce8ae3-4ac8-4a25-b2e3-a313841a625d",
        "Question": "I am unable to access Hardware Access Center for laptop replacement",
        "Locale": "en-US",
        "ChannelId": "directline",
        "GivenName": "John",
        "Surname": "Doe",
        "TenantName": "Instant"
    },
    "Session": {
        "SessionId": "a5d1fe78-d954-47bd-b196-ba4ac5da15d0",
        "StartedUtc": "2022-09-26T10:47:53.7976577+00:00",
        "ChatID": "6btnBr9ATyp5a4onmInj1D-us",
        "ReferrerUrl": "https://chime5-entrybot.azurewebsites.net/admin",
        "CurrentPipelineStage": {
            "Name": "chatend",
            "Type": "SendTextState"
        },
        "PipelinePath": [
            {
                "ToState": "start",
                "ToStateType": "SendTextState",
                "FromState": "StartChat",
                "Timestamp": "2022-09-26T10:47:59.2284505+00:00"
            },
            {
                "ToState": "azurelookup",
                "ToStateType": "KeyPhraseExtractionState",
                "FromState": "start",
                "FromStateType": "SendTextState",
                "Timestamp": "2022-09-26T10:48:02.8726515+00:00"
            },
            {
                "ToState": "chatend",
                "ToStateType": "SendTextState",
                "FromState": "azurelookup",
                "FromStateType": "KeyPhraseExtractionState",
                "Timestamp": "2022-09-26T10:48:23.4607605+00:00"
            }
        ],
        "SkillTagList": [],
        "AverageWaitTime": {
            "String": "0:00:00",
            "Seconds": 0,
            "Minutes": 0,
            "TotalSeconds": 0,
            "TotalMinutes": 0
        },
        "AverageWaitTimeLastHour": {
            "String": "0:00:00",
            "Seconds": 0,
            "Minutes": 0,
            "TotalSeconds": 0,
            "TotalMinutes": 0
        }
    },
    "clientActivityID": "1664189273805oy691xusb5",
    "azurelookup_language": "English",
    "azurelookup_keywords": "hardware,access,center,laptop",
    "azurelookup_entities": "hardware, laptop",
    "System": {
        "CurrentTimeUTC": "2022-09-26T10:48:24.7578914Z",
        "BaseUrl": "https://chime5-entrybot.azurewebsites.net",
        "Tenant": "ChimeV5",
        "PipelineName": "Azure Keyword Extraction Sample",
        "MediaUrl": "https://chime5-entrybot.azurewebsites.net/media/"
    }
}

Orchard JavaScript Methods

Script Method - sendReply

This method sends a chat message to the guest sendReply('message')

Script Method - updateSessionMetaData

This method updates or adds session metadata properties updateSessionMetaData('Key', 'Value')

Script Method - createContent

This method creates a content item in Orchard createContent('ContentType', 'Publish':true|false, {'Content-Properties-As-JSON'})

Example of create content script method:

createContent('EvalRegistration', true, {"DisplayText": "Eval: Form Script, jdoe@domain", "EvalRegistration": {},"TitlePart": {"Title": "Eval: John Doe, jdoe@domain"}})

The JSON Structure of any existing content can be veiwed under the "actions" dropdown of the content item.

Only the following fields need to be included when creating a content item:

{  
  "DisplayText": "Eval: Form Script - Vivek, vgarg@outlook.com",
  "EvalRegistration": {},
  "TitlePart": {
    "Title": "Eval: VG TEST - VG, vgarg@outlook.com"
  }
}

Ticketing JavaScript Methods

Cherwell Ticketing Methods

getCherwellTickets('seekerEmailAddress')

Example:

// Get tickets
var tickets = getCherwellTickets("${Guest.Email}");
var ticketsArray = JSON.parse(tickets);
sendReply("Count of tickets: " + ticketsArray.length);

Response: JSON array of ticket details.
Use Case: Retrieve all tickets related to a specific email.

updateCherwellTicketDescription(ticketNumber, updatedDescription)

Example:

var result = updateCherwellTicketDescription('00070', 'Please engage network team');

Response: Updated ticket record.
Use Case: Update the description of an existing ticket.

assignCherwellTicket(ticketNumber, agentEmailAddress)

Example:

var result = assignCherwellTicket('00070', 'agent@domain');

Response: Updated ticket record.
Use Case: Assign a ticket to a specific agent.


JIRA Ticketing Methods

getJIRATickets('seekerEmailAddress')

Example:

// Get tickets
var tickets = getJIRATickets("${Guest.Email}");
var ticketsArray = JSON.parse(tickets);
sendReply("Count of tickets: " + ticketsArray.length);

Response: JSON array of ticket details.
Use Case: Retrieve tickets associated with an email address.

createJIRATicket(seekerEmailAddress, agentEmailAddress, title, description, project)

Example:

var result = createJIRATicket('seeker@domain', 'agent@domain', 'Incident Title', 'Incident Description', 'project');

Response: JSON object with ticket details.
Use Case: Create a new ticket.

updateJIRATicketTitle(ticketId, updatedTitle)

Example:

var result = updateJIRATicketTitle('00070', 'WiFi issue at NYC hub');

Response: Boolean indicating success or failure.
Use Case: Update the title of a ticket.


ServiceNow Ticketing Methods

getServiceNowTickets('seekerEmailAddress')

Example:

// Get tickets
var tickets = getServiceNowTickets("${Guest.Email}");
var ticketsArray = JSON.parse(tickets);
sendReply("Count of tickets: " + ticketsArray.length);

Response: JSON array of ticket details.
Use Case: Retrieve tickets associated with an email.

createServiceNowTicket('ticketJSON')

Example:

var ticket = {
    state: '0',
    short_description: 'Short Question',
    description: 'Full Question',
    caller_id: 'webvisitor@example.com',
    assigned_to: 'admin@example.com',
    work_notes: 'chat transcript'
};
var result = createServiceNowTicket(JSON.stringify(ticket));

Response: JSON object with ticket details.
Use Case: Create a new ticket.

updateServiceNowTicket('ticketJSON', ticketId)

Example:

var ticket = {
    short_description: 'Updated Short Question',
    description: 'Updated Full Question',
    work_notes: 'Updated chat transcript'
};
var result = updateServiceNowTicket(JSON.stringify(ticket), '<ticketId>');

Response: JSON object with updated ticket details.
Use Case: Update an existing ticket.


SolarWinds Ticketing Methods

getSolarwindsTickets('seekerEmailAddress')

Example:

// Get tickets
var tickets = getSolarwindsTickets("${Guest.Email}");
var ticketsArray = JSON.parse(tickets);
sendReply("Count of tickets: " + ticketsArray.length);

Response: JSON array of ticket details.
Use Case: Retrieve tickets based on a specific email.

createSolarwindsTicket(seekerEmailAddress, agentEmailAddress, title, description)

Example:

var result = createSolarwindsTicket('seeker@domain', 'agent@domain', 'Request for new laptop', 'Current laptop has reached end of life');

Response: JSON object with ticket details.
Use Case: Create a new SolarWinds ticket.

updateSolarwindsTicketDescription(ticketId, updatedDescription)

Example:

var result = updateSolarwindsTicketDescription('00070', 'Please engage network team');

Response: Updated ticket record.
Use Case: Modify ticket description.

assignSolarwindsTicket(ticketId, agentEmailAddress)

Example:

var result = assignSolarwindsTicket('00070', 'agent@domain');

Response: Updated ticket record.
Use Case: Assign a ticket to a specific agent.


For detailed examples and best practices, visit the links provided in the additional FAQs.

Script Methods For AI Summarization

How to use pipeline action: Evaluate JavaScript AI summary commands

Script Editor Enviroment

To assist with script writing, an enviroment has been created with example JSON session Metadata. This enviroment can be accessed from this link.

As changes are made to the script, result and errors are available in real time for review:

Errors are shown in real time:

pipeline, javascript
bmorris