Evaluate JavaScript Pipeline Activity - JavaScript Methods

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

Chime V5 JavaScript Methods

sendReply(msg)

This method sends a chat message to the guest.
Example:

// Send a message to the guest
sendReply('Hello, how can I assist you today?');

Response: The message is sent to the guest.
Use Case: Communicate with the guest during a session.

updateSessionMetaData(key, value)

This method updates or adds session metadata properties.
Example:

// Update session metadata
updateSessionMetaData('Guest.Email', 'John.Doe@example.com');
// All of a sessions metadata properties can be accessed through JavaScript using the following format:
sessionMetaData.<Metadata Variable>

Response: Session metadata is updated or added with the specified key-value pair.
Use Case: Store or update session-specific metadata for better tracking or handling.
Note: Additional Metadata information can be found in the Metadata section below


Azure Graph Methods

getUser(emailAddress) : userObject

This method retrieves a user object by email address.
Example:

// Retrieve user details
var user = getUser('user@domain.com');
sendReply("User Name: " + user.name + ", Role: " + user.role);

Response: The user object with details is retrieved.

getUserOfficeLocation(emailAddress) : string

This method retrieves the office location of a user by their email address.
Example:

// Retrieve user office location
var location = getUserOfficeLocation('user@domain.com');
sendReply("User Office Location: " + location);

Response: The office location of the specified user is retrieved.

createMeetingWithJoinUrl() : meetingObject

This method creates a meeting and generates a join URL.
Example:

// Create a meeting with a join URL
var meeting = createMeetingWithJoinUrl();
sendReply("Meeting URL: " + meeting.url);

Response: A meeting is created, and the join URL is returned.

getADUserObject (emailAddress) : userObject

This method retrieves a specified user object or performs a search to get multiple user objects.
Example:

// Retrieve a specific AD user object
var userObject = getADUserObject('username@domain.com');
var userDetails = JSON.parse(userObject);

// Access user properties
sendReply("User Display Name: " + userDetails.displayName + ", Email: " + userDetails.email);

Response: JSON object with user details.
Use Case: Retrieve details for a specific user or search for multiple user objects.


Chat GPT Methods

runPrompt (sessionId, prompt) : string

This method processes a prompt through ChatGPT and returns a response based on the specified rules.
Example:

// Run a prompt through ChatGPT
var result = runPrompt(sessionMetaData.Session.SessionId, 
    "If there is no message from the user yet, then respond with \"getQuestion\"\n" +
    "If the user's question is about printers, then respond with \"printers\"\n" +
    "If the user's question is about email, then respond with \"email\"\n" +
    "Otherwise, respond with \"otherProblem\"");

// Handle the response
sendReply("ChatGPT Response: " + result);

Response: A string value indicating the response based on the rules provided in the prompt.

summarizeConversation(sessionId) : JSON

This method summarizes a conversation based on the provided session ID.
Example:

// Summarize the conversation
let sessionId = "${Session.SessionId}";
let summary = summarizeConversation(sessionId);

// Access summary details
sendReply(summary.SummaryTitle);
sendReply(summary.Issue);
sendReply(summary.Narrative);
sendReply(summary.Resolution);

Response: A JSON object containing the conversation summary, including the title, issue, narrative, and resolution, is returned.


FAQ Methods

getFAQTags() : string[]

This method retrieves all available FAQ tags.
Example:

// Retrieve FAQ tags
var tags = getFAQTags();
sendReply("Available tags: " + tags.join(', '));

Response: A list of FAQ tags is retrieved.

searchFAQByTag(tag) : FAQ[]

This method searches FAQs by a specific tag.
Example:

// Search FAQs by tag
var faqs = searchFAQByTag('network-issues');
sendReply("FAQs found: " + faqs.length);
faqs.forEach(faqRecord => {
    sendReply("Id: " + faqRecord.ContentItemId + ", displayText: " +  faqRecord.displayText + " PublishedUtc: " + faqRecord.PublishedUtc);
});

Response: A list of FAQs matching the specified tag is returned.

searchFAQByTitleKeywords(keywords) : FAQ[]

This method searches FAQs by title keywords.
Example:

// Search FAQs by title keywords
var faqs = searchFAQByTitleKeywords('connectivity');
sendReply("FAQs found: " + faqs.length);
faqs.forEach(faqRecord => {
    sendReply("Id: " + faqRecord.ContentItemId + ", displayText: " +  faqRecord.displayText + " PublishedUtc: " + faqRecord.PublishedUtc);
});

Response: A list of FAQs matching the title keywords is returned.


Ticketing Methods

Cherwell Ticketing Methods

getCherwellTickets('seekerEmailAddress') : JSONArray[]

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) : JSON

Example:

var ticketObject = updateCherwellTicketDescription('00070', 'Please engage network team');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL Use Case: Update the description of an existing ticket.

assignCherwellTicket(ticketNumber, agentEmailAddress) : JSON

Example:

var ticketObject = assignCherwellTicket('00070', 'agent@domain');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL Use Case: Assign a ticket to a specific agent.


JIRA Ticketing Methods

getJIRATickets('seekerEmailAddress') : JSONArray[]

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) : JSON

Example:

var ticketObject = createJIRATicket('seeker@domain', 'agent@domain', 'Incident Title', 'Incident Description', 'project');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

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

updateJIRATicketTitle(ticketId, updatedTitle) : JSON

Example:

var ticketObject = updateJIRATicketTitle('00070', 'WiFi issue at NYC hub');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL Use Case: Update the title of a ticket.


ServiceNow Ticketing Methods

getServiceNowTickets('seekerEmailAddress') : JSONArray[]

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') : JSON

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) : JSON

Example:

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

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

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


SolarWinds Ticketing Methods

Solarwinds Ticketing FAQ

getSolarwindsTickets('seekerEmailAddress') : JSONArray[]

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) : JSON

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) : JSON

Example:

var ticketObject = updateSolarwindsTicketDescription('00070', 'Please engage network team');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL
Use Case: Modify ticket description.

assignSolarwindsTicket(ticketId, agentEmailAddress) : JSON

Example:

var ticketObject = assignSolarwindsTicket('00070', 'agent@domain');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL
Use Case: Assign a ticket to a specific agent.

addCommentsToSolarwindsTicket(sessionMetaData.Ticket.Id, summary, false)

This method generates a session comments based on the provided session metadata.
Example:

// Generate the session summary
let summary = "VTB Session Summary (AI Generated)\n\n";
summary += "AI Issue Title\n";
summary += sessionMetaData.AI.Summary.Title + "\n\n";
 
summary += "AI Issue Description\n";
summary += sessionMetaData.AI.Summary.Issue + "\n\n";
 
summary += "AI Narrative\n";
summary += sessionMetaData.AI.Summary.Narrative + "\n\n";
 
summary += "AI Resolution\n";
summary += sessionMetaData.AI.Summary.Resolution + "\n\n";
 
// Add the summary as comments to the ticket
addCommentsToSolarwindsTicket(sessionMetaData.Ticket.Id, summary, false);

Response: The session summary string is generated and added to the SolarWinds ticket.


Invgate Ticketing Methods

getInvgateTickets('seekerEmailAddress') : JSONArray[]

Example:

// Get tickets
var tickets = getInvgateTickets("${Guest.Email}");
var ticketsArray = JSON.parse(tickets);

// Perform operations on ticket records
sendReply("Count of tickets: " + ticketsArray.length);

Response: JSON array of ticket details.
Use Case: Retrieve a list of Invgate tickets associated with a specific email address.

updateInvgateTicketDescription(ticketId, description) : JSON

Example:

// Update ticket description
var ticketObject = updateInvgateTicketDescription('00070', 'Please escalate to the IT team for further analysis.');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL
Use Case: Update the description of a ticket.

assignInvgateTicket(agentEmailAddress) : JSON

Example:

// Assign ticket to an agent
var ticketObject = assignInvgateTicket('agent@domain');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL
Use Case: Assign a ticket to a specific agent.

updateInvgateTicketTitle(ticketId, title) : JSON

Example:

// Update ticket title
var ticketObject = updateInvgateTicketTitle('00070', 'Network Issue: Unable to Connect');
var ticketDetails = JSON.parse(ticketObject);

// Access ticket properties
sendReply("Ticket Id: " + ticketDetails.Id + ", URL: " + ticketDetails.URL);

Response: Updated ticket object with ticket properties: Id, Number, TicketState, URL
Use Case: Update the title of a ticket.


Deflection Methods

markDeflected(isDeflected)

This method marks the conversation as deflected based on a boolean value.
Example:

// Mark the conversation as deflected
markDeflected(true);

Response: The conversation is marked as deflected. The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.State = "Deflected"

markDeflectedByCustom(reason)

This method marks the conversation as deflected with a custom reason.
Example:

// Mark the conversation as deflected with a custom reason
markDeflectedByCustom('Resolved through knowledge base lookup');

Response: The conversation is marked as deflected with the specified reason.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = reason
  • Session.State = "Deflected"

markDeflectedByFaqLookup()

This method marks the conversation as deflected after an FAQ lookup.
Example:

// Mark the conversation as deflected by FAQ lookup
markDeflectedByFaqLookup();

Response: The conversation is marked as deflected due to an FAQ lookup.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = "FAQLookup
  • Session.State = "Deflected"

markDeflectedByTicketListing()

This method marks the conversation as deflected after a ticket listing.
Example:

// Mark the conversation as deflected by ticket listing
markDeflectedByTicketListing();

Response: The conversation is marked as deflected due to a ticket listing.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = "ShowTickets"
  • Session.State = "Deflected"

markDeflectedByOutageDisplay()

This method marks the conversation as deflected due to an outage display.
Example:

// Mark the conversation as deflected by outage display
markDeflectedByOutageDisplay();

Response: The conversation is marked as deflected due to an outage display.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = "Outage"
  • Session.State = "Deflected"

markDeflectedByAIAssist()

This method marks the conversation as deflected by AI assistance.
Example:

// Mark the conversation as deflected by AI assistance
markDeflectedByAIAssist();

Response: The conversation is marked as deflected due to AI assistance.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = AI Assist
  • Session.State = "Deflected"

markDeflectedByOffHours()

This method marks the conversation as deflected during off-hours.
Example:

// Mark the conversation as deflected during off-hours
markDeflectedByOffHours();

Response: The conversation is marked as deflected due to off-hours.The call sets the following Metadata values:

  • Session.Deflected = true
  • Session.DeflectedBy = Off Hours
  • Session.State = "Deflected"

No User Response Methods

noUserResponseCustomReason(reason)

This method indicates no user response with a custom reason.
Example:

// Log no user response with a custom reason
noUserResponseCustomReason('User did not engage after viewing options');

Response: The lack of user response is logged with the specified custom reason.

noUserResponseAfterFAQLookup()

This method indicates no user response after an FAQ lookup.
Example:

// Log no user response after FAQ lookup
noUserResponseAfterFAQLookup();

Response: The lack of user response after the FAQ lookup is logged.

noUserResponseAfterTicketListing()

This method indicates no user response after viewing ticket listings.
Example:

// Log no user response after viewing ticket listings
noUserResponseAfterTicketListing();

Response: The lack of user response after ticket listings is logged.

noUserResponseAfterTicketCreation()

This method indicates no user response after ticket creation.
Example:

// Log no user response after ticket creation
noUserResponseAfterTicketCreation();

Response: The lack of user response after ticket creation is logged.

noUserResponseAfterOutageDisplay()

This method indicates no user response after viewing an outage display.
Example:

// Log no user response after outage display
noUserResponseAfterOutageDisplay();

Response: The lack of user response after the outage display is logged.

noUserResponseAfterAIAssist()

This method indicates no user response after receiving AI assistance.
Example:

// Log no user response after AI assistance
noUserResponseAfterAIAssist();

Response: The lack of user response after AI assistance is logged.

noUserResponseAfterFeedbackCard()

This method indicates no user response after displaying a feedback card.
Example:

// Log no user response after feedback card
noUserResponseAfterFeedbackCard();

Response: The lack of user response after the feedback card is logged.

noUserResponseAfterQuestionPrompt()

This method indicates no user response after prompting a question.
Example:

// Log no user response after a question prompt
noUserResponseAfterQuestionPrompt();

Response: The lack of user response after the question prompt is logged.

noUserResponseAfterOffHoursPrompt()

This method indicates no user response after an off-hours prompt.
Example:

// Log no user response after off-hours prompt
noUserResponseAfterOffHoursPrompt();

Response: The lack of user response after the off-hours prompt is logged.


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:


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 - 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"
  }
}
pipeline, javascript
bmorris