ReplyCX Documentation
Login
  • ⛩️Welcome to ReplyCX Knowledge Base! 📚
    • ReplyCX Basics
  • ▶️GETTING STARTED
    • Building a Chatbot
    • Testing a Chatbot
    • Channel Configurations
    • Deploying a Chatbot
    • Utility Tools
  • 🧩ACTION BLOCKS
    • Overview
    • Trigger
    • Send Message
    • Collect Input
    • Buttons
    • Carousel
    • Calendar
    • Send an Email
    • Condition
    • Image Carousel
    • Human Handover
    • Slider
    • Collect File
    • Delay
    • Form
    • Flow
    • Code-block
    • Options
    • Jump
    • List
    • Reply Button
    • AI Model
    • SET AI
    • Answer AI
    • AI AGENT
    • Webhook
    • Javascript
    • Send Status
    • Http Request
    • Dynamic data
    • Whatsapp flow
  • 🦾AI Studio
    • Building a GPT Chatbot
    • Knowledge Base
    • Training on historical live chat to generate response
    • Retrain frequency for URL data source
    • Custom Answers
    • Function Call
    • Prompts
    • Tokens
    • Setting up retrain
    • Advanced Crawling Criteria
  • ⛓️Integrations
    • Types of Integrations
    • Service Call
    • Google Sheets
      • Support for “Update Record” in Google Sheets
    • Codeblock
    • Google Calendar
    • Calendly
    • Zoho CRM
    • Hubspot
    • Dialog Flow
    • Events
    • Google Analytics
    • Freshdesk
    • Salesforce
    • Zapier
    • Airtable
    • Public API's
  • 🟢WhatsApp Business API
    • Prerequisites
    • WhatsApp Business API - Meta
    • Using a test WhatsApp Business API account
    • Product catalog on WhatsApp
    • Sync WhatsApp Template
    • Support for Carousel template message
  • Instagram
    • Using the Instagram Channel
  • 💬Live Chat
    • Overview
    • Saved Replies
    • Manage Saved Replies
    • Message status on live chat
    • Generating Response Using AI.
    • Rewriting existing response with AI
    • Labels
    • Managing Labels
    • Qualification details covered during a conversation
    • Settings
    • Filter conversations
    • Conversation History
    • Close a conversation
    • Related / Past Conversations
    • Elements on conversation card
    • Kind of Conversation Status
    • Copy Chat Transcript of a Conversation
    • Customize Live Chat Screen
    • Restart Conversation
    • Blocking Contacts
    • Agent status on live chat
    • Edit Variables in Closed Chat
  • ⚙️Troubleshooting
    • Variable Manager
    • Fallback Variables
    • Human Handover Configuration
    • Clone a bot
    • Preffered Image Dimensions
    • Working of Link Tracking
    • Setting up variables using trigger block
    • Availability of agents in Human Handover
    • Creating loop in the conversational flow
    • Requesting Edit Access
    • Cookies
    • Creating Custom Role
  • 📢Outbound Bots
    • Outbound Action Blocks
      • Delay
      • Send WhatsApp
      • Send SMS
      • Send Email
    • Building a One-Off Campaign
    • Building a Ongoing Campaign
    • Creating WhatsApp Templates
  • 📱Chat Widget Customization
    • Embedding Chat Widgets
    • Customize Chat Widget UI using CSS
    • Display Chat Widget in iFrame
    • Change Appearance
    • Chat widget 3.0
  • 🏦Account Management
    • Manage Teams
    • Manage Teammates
    • Manage Roles
      • Channel configuration Permission
    • Opt Out Management
  • 📊Reporting
    • Custom Reports
    • Contacts Feature Recap
    • Scheduling Contact Report
    • Weekly Reports and Interactions
    • Export a contact list
    • Tracking link clicks on chatbot messages
    • Agent Report
    • AI Agent Report
    • Outbound Report
  • 🧑‍💻 Support
    • Forget Password
Powered by GitBook
On this page
  • Maths Calculations:
  • Rendering values into variables:
  • String Modification:
  • Triggering day-based flow:
  • Triggering and monitoring events in Google Analytics or any other analytics tool:
  • JS execution in async

Was this helpful?

  1. ACTION BLOCKS

Javascript

Executes a javascript code on the client side

PreviousWebhookNextSend Status

Last updated 3 months ago

Was this helpful?

JavaScript is a script that runs in the browser to execute various actions. Some common use cases for a JavaScript action block include:

  • Performing mathematical calculations.

  • Dynamically updating variable values.

  • Modifying strings.

  • Triggering and tracking events in Google Analytics.

Select Javascript action block in Replycx bot flow.

Maths Calculations:

Here are some code snippets you can use to perform mathematical calculations within the chatbot flow:

Parameter

Snippets

Description

Summation (Addition)

const additionResult = num1 + num2;

  • Num 1 and Num 2 can be any number or a variable containing a numeric value.

  • The result will be stored in the additionResult variable.

Subtraction (Minus)

const additionResult = num1 - num2;

  • Num 1 and Num 2 can be any numeric value or a variable containing a number.

  • The result will be saved in the additionResult variable.

Division (Divide)

const additionResult = num1 / num2;

  • Num 1 and Num 2 can be any numeric value or a variable containing a stored number.

  • The result will be stored in the additionResult variable.

Multiplication (Multiple)

const additionResult = num1 * num2;

  • Num 1 & Num 2 can be any number or variable which has a number stored in it

  • The result will be stored in additionResult variable

Rendering values into variables:

Here are some snippets you can use to dynamically render values in variables.

Parameter

Snippet

Example

Set Variable (Conversation)

cx.setConversationVariable(“variable_name”,”variable_value”);

Or

replycx.setConversationVariables({“variable_name”:”variable_value”})

cx.setConversationVariable(“name_wn”,”ABC”);

Or

replycx.setConversationVariables({“t1”:”123”})

Set Variable (Contact)

cx.setContactVariable(“variable_name”,”variable_value”);

Or

replycx.setContactVariables({“variable_name”:”variable_value”})

cx.setContactVariable(“name_wn”,”ABC”);

Or

replycx.setContactVariables({“t1”:”123”})

String Modification:

Here are some snippets you can use to determine the length of a string or extract a portion of its value.

Parameter

Snippet

Example

Length of String

const lengthOfString = “variable_name”.length();

const lengthOfString = “some_string_content”.length();

//Output: 19

Calculates the number of characters passed/present in the value

Get part of a string

const partOfString = “variable_name”.slice();

const partOfString = “some_string_content”.slice(5);

Note: We need to pass the starting index from where we need to get the sub-string. The index starts from 0.

//Output: string_content

Commonly used to pass the phone number without country code

Triggering day-based flow:

Here is a snippet you can use to trigger the flow based on a specific day.

Parameter

Snippet

Description

Get current date

const currentDate = new Date();

Helps retrieve today's date.

Check if From date should be more than To date

isFromDateBeforeToDate(fromDate, toDate) {

const fromDateObj = new Date(fromDate);

const toDateObj = new Date(toDate);

return fromDateObj < toDateObj;

}

Helps to trigger the day-specific flow.

Triggering and monitoring events in Google Analytics or any other analytics tool:

Here is a snippet you can use to log or track events in Google Analytics or any other analytics tool.

Tool

Snippet

Example

Google Analytics 4

window.dataLayer = window.dataLayer || [];

function gtag() {

window.dataLayer.push(arguments);

}

gtag("js", new Date());

gtag("config", "YOUR-MEASUREMENT-ID");

gtag("event", "YOUR-EVENT-NAME", {

"send_to": "YOUR-MEASUREMENT-ID"

// Additional parameters that you may want to pass

});

window.dataLayer = window.dataLayer || [];

function gtag() {

window.dataLayer.push(arguments);

}

gtag("js", new Date());

gtag("config", "123");

gtag("event", "Replycx_Test", {

"send_to": "123",

"name": "Test",

"phone": "123456789",

});

JS execution in async

JavaScript can be run asynchronously, allowing the bot to continue the conversation without waiting for the script to complete. This results in a smoother and faster chat experience.

How to enable: Go to JavaScript block → Enable "Execute asynchronously".

🧩