Scripts let you add more advanced interactions to your chatbot, such as:
- Saving, resetting, and retrieving variable values.
- Starting different passages based on variable values, business hours, or values from a data store.
- Interacting with other platforms such as Shopify.
- Sending messages with dynamic content or custom Quick Replies.
- Using guardrails and sending messages to the chatbot log.
- Sending emails.
Testing changes to your scripts
Changes to your scripts are available immediately in TestBot for testing. Your changes won't impact your live chatbot until you publish them.
Message limits
Chatbot scripts can send a maximum of one message to the user per script. Any subsequent messages you try to send within the same script will not be sent to the user. You can add multiple script bubbles to a passage if you need to send more than one dynamic message to a user.
Keep your content in passages
Scripts give you powerful capabilities, but writing a lot of chatbot-content inside your scripts can make it hard for the content creators to maintain the chatbot. Where possible, write your content in passages you direct the chatbot to, rather than in scripts.
Timezones and locales
You can use moment.js to manage timezone-aware dates and times, but chatbot scripts can't set a global moment.js timezone or locale: timezones and locales must be set within each script.
To set the timezone or locale in a chatbot script:
- Instantiate a moment object with the timezone and locale you want to use.
- Use that moment object within your script instead of the usual moment instance.
//Instantiate the moment object with the timezone and locale
const getMoment = (time) => moment(time).tz('Australia/Melbuourne').locale('en-au');
//Use the instantiated object
const current = getMoment();
console.log(getMoment().toLocaleString());
console.log(getMoment(current).set({h:8}).toLocaleString());
console.log(getMoment(current).set({h:17}).toLocaleString());
console.log(getMoment(current).isoWeekday());
//Always end your chatbot script execution with done();
done();
Ending script execution
Wherever the script has finished executing, you must call the done() method to tell the chatbot to return to the conversation flow.
See done(err).
Chatbot methods
Chatbot scripts are written in JavaScript, with some additional libraries provided within the platform (see Provided libraries). The chatbot also provides methods for most chatbot activities you can accomplish within the inGenious AI platform:
| Namespace | |
|---|---|
| User | Get and set user data, subscribe to broadcasts, and schedule notifications. |
| Channel | Send messages, display typing indicators, and manage handovers and handbacks. |
| Flow | Send the chatbot to a specific conversation or start a passage. |
| Util | Send emails to one or more email addresses. |
| Datastore | Use and manage additional data in your scripts. |
| Analytics | Send additional attributes to Mixpanel. |
| Shopify | Interact with your Shopify products and shopping carts. |