WotNot Help Center
Create a ticketBook a demoProduct
  • 👋Welcome!
  • 🏁Getting Started
    • Building a chatbot
    • Testing a chatbot
    • Publishing your bot
      • Web
        • Embed chatbots on website
      • WhatsApp
        • Meta
        • 360Dialog
        • Twilio
        • GupShup
        • TechAlpha
      • Instagram
      • Facebook Messenger
      • SMS
      • Mobile app
      • API
    • Utility Tools
    • Contacts
      • Scheduling a Contact Report
      • Exporting a Contact List
      • Blocking contacts
    • Chatbot Appearance
      • Custom CSS
      • Image dimensions
      • Pop-up messages
  • ⚒️Bot builder
    • Action blocks
      • Trigger
      • Send message
      • Collect input
      • Buttons
      • Reply buttons
      • Carousel
      • Agent
      • Answer AI
      • Set AI
      • Send an email
      • List
      • Condition
      • Talk to human
      • Dynamic data
      • Javascript
      • Collect file
      • Form
      • Webhook
      • Flow
      • Jump
      • Options
      • Calendar
      • Delay
      • Codeblock
      • Slider
      • Image gallery
      • Send WhatsApp
      • Send SMS
      • Send Email
      • Send Status
      • WhatsApp flow
      • Catalogue
    • Outbound bots
      • Building One Off Campaign
      • Building Ongoing Campaign
    • Variables
    • Cloning bots
    • Requesting edit access
    • Connecting action blocks
    • Creating a loop
  • ✨AI Studio
    • Building a GPT chatbot
    • Knowledge base
    • Custom Answers
    • Functions
    • Prompts
    • AI credits
    • Refresh frequency
  • 💬Live Chat
    • Overview
    • Building a bot with live chat
    • Creating views
    • Adding labels
    • Saved replies
    • Settings
  • 🔗Integrations
    • Overview
    • HTTP request
    • Ready integrations
      • Google Calendar
      • Google Sheets
      • Google Analytics
        • Using Javascript
      • Salesforce
      • HubSpot
      • Calendly
      • Slack
      • Airtable
      • Zendesk
      • Freshdesk
      • DialogFlow
      • Zoho CRM
    • Events
    • Zapier
    • Public APIs
  • 💬WhatsApp Business API
    • Getting a WhatsApp API
      • Getting WhatsApp API (Old approach)
      • Sandbox WhatsApp API
    • Facebook Business Manager (FBM) Verification
    • Creating a WhatsApp Template
    • Cost
    • Messaging Limits, Quality Rating
    • Official Business Account (Green tick verification)
  • 📊Reporting
    • Overview
    • Chatbot Report
    • Agent Report
    • Outbound Report
    • Link analytics
    • Weekly email report
  • 🛠️Troubleshooting
    • Getting notification for leads
    • JS functions to trigger chat widget
    • Opt-out management
    • Setting up link tracking
    • How do I hard refresh my browser?
    • Cookies
    • Notifications
    • Tracking Facebook Pixel
    • Setting up SSO login
    • Inviting teammates
    • Teams
  • 🧑‍💻Support
    • Creating a ticket
    • Book a demo
    • Purchasing a subscription
    • Cancelling a subscription
    • Refund policy
    • Reset password
    • Deleting account
Powered by GitBook
On this page
  • Maths Calculations:
  • Rendering values into variables:
  • String Modification:
  • Firing & Tracking events in Google Analytics or any Analytics tool:
  • Triggering day-based flow:

Was this helpful?

  1. Bot builder
  2. Action blocks

Javascript

Executes a javascript code on the client side.

Javascript is basically a piece of code that can be run on the browser to perform an action. Some of the cases where a Javascript action block can be used are:

  • Performing maths calculations.

  • Dynamically rendering the values of the variables.

  • String modification.

  • Firing & tracking events in Google Analytics.

You can choose to run the Javascript code either on CLIENT / SERVER.

Maths Calculations:

Here are few of the snippets that you can use to perform the maths calculations within the chatbot flow:

Parameter
Snippet
Description

Summation (Addition)

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

Subtraction (Minus)

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

Division (Divide)

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

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 few of the snippets that you can use to render values in variables.

Parameter
Snippet
Example

Set Variable (Conversation)

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

Or

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

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

Or

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

Set Variable (Contact)

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

Or

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

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

Or

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

String Modification:

Here are few of the snippets that you can use to calculate the length of the variable or get part of the variable.

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

Firing & Tracking events in Google Analytics or any Analytics tool:

Here is the snippet that you can use to push or record events into 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", "WotNot_Test", {

"send_to": "123",

"name": "Test",

"phone": "123456789",

});

Triggering day-based flow:

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

Parameter
Snippet
Description

Get current date

const currentDate = new Date();

Helps to get the today’s date

Check if Fromdate should be more than Todate

isFromDateBeforeToDate(fromDate, toDate) {

const fromDateObj = new Date(fromDate);

const toDateObj = new Date(toDate);

return fromDateObj < toDateObj;

}

Helps to trigger the flow the day specific flow

PreviousDynamic dataNextCollect file

Last updated 11 months ago

Was this helpful?

⚒️