Please make sure you sign up with the same account with which you would like to create and maintain the app from. Transferring apps/wallet balance from one account to another in future would not be possible
By logging in, you are agreeing to the Terms of Service and the Privacy Policy.
Want to outsource bot development? We have partners to get it done. Click here to get in touch
This guide will illustrate how you can build, deploy and test a plain text (simple message) bot on WhatsApp using bot scripting tool. If you aren't familiar with our Bot Scripting tool, do read our earlier guides to get acquainted.
Let us create a simple chatbot that asks the user for his/her favorite publication and then prints the day's top article from that publication.
Let's start by creating a new bot in IDE mode, we will call it 'TechNewsBot'. Now begin by asking the user for their publication preference, to do this we will write a introductory message under [main] module of the default.scr file.
[main]
introMessageLabel: Hey there! Do you prefer reading Wired or TechCrunch?
Label introMessageLabel is a bot response asking for user's preference.
Now, let's set the user's preference based on his/her reply.
[main]
introMessageLabel: Hey there! Do you prefer reading Wired or TechCrunch?
userResponseLabel: wired | techcrunch
botResponseLabel: {{userPublicationPreferenceResp}}
Assuming a user's input will be either “wired” or “techcrunch”, let's write a handler for the label userResponseLabel to store his/her preference and accordingly send out a dynamic message at label botResponseLabel
There are two types of inbuilt data persistence options provided in our platform: Botleveldata and Roomleveldata. The former stores common data for the bot for all its users across all channels while the latter stores data for each user on a specific messaging channel. For our example, our users preference is unique to WhatsApp hence, we will be using roomleveldata.
{{userPublicationPreferenceResp}} is a variable declared at label botResponseLabel whose value will be set by the handler function under default.js file (This file contains handler for all the labels declared in the default.src file.)
default.js file should be created by the developer
module.exports.main = {
userResponseLabel: (options, event, context, callback) => {
var userMessage = event.message;
if (userMessage.indexOf("wired") > -1) {
publicationName = "wired";
} else if (userMessage.indexOf("techcrunch") > -1) {
publicationName = "techcrunch";
}
context.simpledb.roomleveldata.publication = publicationName;
options.data.userPublicationPreferenceResp = "Type 'read' to get latest article from " + publicationName;
callback(options, event, context);
}
}
There is a possibility that a user might give his reference in a free flowing text meaning a user can opt-in for his/her preference in a form of a sentence for example: “I would prefer reading articles from Wired publication” or he/she may simply say “Wired”. Our NLP engine takes care of identifying the entities Wired or TechCrunch given at label userResponseLabel so, in the above code we are just checking for keyword existence to set the publication. In case the engine is unable to identify the entities at that particular instance, it will throw a fall back message saying “Sorry error occurred”. You may customize the generic fallback message from index.js file.
Once the user's preference is store and the bot sends out a dynamic message, a user can type keyword 'read' to get the latest article.
[main]
introMessageLabel: Hey there! Do you prefer reading Wired or TechCrunch?
userResponseLabel: wired | techcrunch
botResponseLabel: {{userPublicationPreferenceResp}}
userAskingForArticle: read
botResponseLabelForNews: {{article}}
Whenever the users response is received, we will make an HTTP call to the publication's RSS feed. The RSS feed returns 10 top stories from the publication selected. Our IDE facilitates the HTTP calls using either in-built modules or using 3rd party Node modules (like request, Unirest, etc). In this case, we will be using the Node module request to make a GET HTTP call to the publication's RSS feed endpoint.
Now, before writing a handler for label userAskingForArticle let's, first import 'request' module in the default.js file and install the module using built-in Terminal.
Now, let's write a handler for our label userAskingForArticle. This handler will retrieve user's stored preference and make a call to function getFeed().
const request = require("request");
module.exports.main = {
userAskingForArticle: (options, event, context, callback) => {
var userPreference = context.simpledb.roomleveldata.publication;
getFeed(userPreference, (randomArticle) =>{
options.data.article = randomArticle
callback(options, event, context);
});
}
}
function getFeed(publication, callbackFunction) {
var options = {
method: 'GET',
url: 'https://api.rss2json.com/v1/api.json',
qs: {
rss_url: 'https://' + publication + '.com/feed'
},
};
request(options, function(error, response, body) {
if (error) throw new Error(error);
var respJson = JSON.parse(body); //parses the response
var stories = respJson.items;
// Chose a random article from the parsed response
var resp = "";
var randomnumber = Math.floor(Math.random() * (stories.length - 1 + 1)) + 1;
resp = resp + stories[randomnumber].title + "\n" + stories[randomnumber].link + "\n";
resp = resp.replace(" ", "");
if(callbackFunction)
{
callbackFunction(resp)
}
});
}
getFeed() is the function that makes a HTTP call and handles responses to that HTTP call at the RSS feed endpoint. In response to the HTTP call the RSS feed returns a JSON object which needs to be parsed. This JSON object contains 10 articles each with attributes such as 'title', 'author', 'link' and more. For this example, we will choose the title and web link for a randomly chosen article.
That's it! You have now created a simple bot on IDE for WhatsApp.
It is always recommended that you test your bot locally before deploying your changes on production. IDE comes with an inbuilt web widget for testing. This web widget allows you to test the bot code before deploying it on the production server. To access the web widget you need to start the server first. Right-click on the bot project and select “Start Server” option, this will start a local server on port 8081. Once the server is started you can then click on the “Chat Widget” icon from the list of options at the bottom of IDE.
Once you are ready to go live, you can deploy your bot on production.
To deploy your bot code on production, right-click on the bot project and select “Deploy on Prod” option, this will start the deployment procedure and on completion you will get a deployment success message.
Let's test the bot that we've built by using the Gupshup Proxy Bot. The Proxy Bot is a essentially testing tool developed by Gupshup that can mimic any bot developed on the Gupshup Bot Builder. You will find the Proxy Bot on all messaging channels such as WhatsApp, Facebook Messenger, Slack etc.
To get Gupshup Proxy Bot on WhatsApp simply message 'hi' to Phone number: +917834811114 | You can invoke a bot that you have created by using the keyword 'proxy' followed by your 'bot name'. In this case 'proxy TechNewsBot'. |
![]() |
![]() |
To bind your Gupshup bot with your WhatsApp Business number, you will have to publish your bot on WhatsApp for Business using our publishing mechanisms.
WhatsApp is in a limited public preview. Hence, if you'd like to have a bot with your business identity, submit information about your business for consideration as WhatsApp continues to expand its availability. Or you may reach out to us to apply for early access, with Gupshup as your official solution provider for WhatsApp Business
To do so, go to the My bots section, click Channel button of the bot which you want to publish. You will then be redirected to a list of channels - search for WhatsApp for Business channel and click Publish button. You will see a list of steps - Follow the steps as mentioned to publish your bot.
This website uses the following types of cookies: strictly necessary, functional and performance cookies. To know more information regarding how these cookies may impact your experience, please click on Settings.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Name | Provider | Purpose | Expiry | Type |
---|---|---|---|---|
CookieConsent | CookieBot | Stores the user's cookie consent state for the current domain | 1 year | HTTP |
smacon | www.gupshup.io | Authenticating user to access our website | Session | HTTP |
rc::c rc::b |
This cookie is used to distinguish between humans and bots. | Session | HTTP | |
JSESSIONID | www.gupshup.io | Preserves users states across page requests. | Session | HTTP |
gipuserid | www.gupshup.io | Collect & store User ID for easy accessibility | 5 years | HTTP |
__stripe_mid | www.gupshup.io | Stripe is used to make credit card payments in our application. Stripe uses this cookie to remember who you are and process payments without storing any credit card information on our servers. Know more | 1 year | First party |
__stripe_sid | www.gupshup.io | Stripe is used to make credit card payments in our application. Stripe uses this cookie to remember who you are and process payments without storing any credit card information on our servers. Know more | 30 minutes | First party |
These cookies enable the website to provide enhanced functionality and personalisation such as the website content being provided in the preferred language for your location. They may be set by us or by third party providers whose services we have added to our pages.
Name | Provider | Purpose | Expiry | Type |
---|---|---|---|---|
gs_lang_pref | www.gupshup.io | Remember the user's selected language version of a website. This allows the website to show content most relevant to that language. | Session | HTTP |
These cookies allow us to measure visits, traffic sources and engagement so we can improve the performance of our site. They help us learn which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous.
Name | Provider | Purpose | Expiry | Type |
---|---|---|---|---|
_ga | www.gupshup.io | Registers a unique ID that is used to generate statistical data on how the visitor uses the website. Know more | 2 years | HTTP |
_ga_# | www.gupshup.io | Used by Google Analytics to collect data on the number of times a user has visited the website as well as dates for the first and most recent visit. Know more | 2 years | HTTP |
_gat | www.gupshup.io | Used by Google Analytics to throttle request rate. Know more | 1 day | HTTP |
_gid | www.gupshup.io | Registers a unique ID that is used to generate statistical data on how the visitor uses the website. | 1 day | HTTP |
__utmz | www.gupshup.io | Stores the traffic source or campaign that explains how the user reached your site. The cookie is created when the javascript library executes and is updated every time data is sent to Google Analytics. Know more | 6 months | HTTP |
__utma | www.gupshup.io | Used to distinguish users and sessions. The cookie is created when the javascript library executes and no existing __utma cookies exists. The cookie is updated every time data is sent to Google Analytics. Know more | 2 years | HTTP |
initialTrafficSource | www.gupshup.io | Used by Google Tag Manager to track the initial traffic source of the visitor. | 2 years | HTTP |
We may use cookies, web beacons, tracking pixels, and other tracking technologies when you visit our website gupshup.io including any other media form, media channel, mobile website, or mobile application related or connected thereto (collectively, the “Site”) to help customize the Site and improve your experience.
We reserve the right to make changes to this Cookie Policy at any time and for any reason. We will alert you about any changes by updating the “Last Updated” date of this Cookie Policy. Any changes or modifications will be effective immediately upon posting the updated Cookie Policy on the Site, and you waive the right to receive specific notice of each such change or modification.
You are encouraged to periodically review this Cookie Policy to stay informed of updates. You will be deemed to have been made aware of, will be subject to, and will be deemed to have accepted the changes in any revised Cookie Policy by your continued use of the Site after the date such revised Cookie Policy is posted.
Cookie Policy (“Policy”) provides detailed information about cookies and JavaScript libraries, how we use them, and how you can manage them when you visit Gupshup website (“website”).
Cookies make it easy and efficient for you to navigate and interact with the Gupshup website. Cookies are small text files that we place on your device (e.g. computer or smartphone) when you visit our website. We will always ask your consent to set cookies e.g., to remember your preferences that are more relevant to you.
Cookies which are necessary for the website to function cannot be switched off.
You can at any time change or withdraw your consent from the Cookie Declaration on our website. (see "Cookie Consent" below in footer).
Learn more about who we are, how you can contact us and how we process personal data in our Privacy Statement.
Your consent applies to the www.gupshup.io domain only.
Cookies are used to make the user's web experience faster, convenient and personalised. For example you can select a language to view a website the first time you visit it. When you visit the website again it will save your preference.
Session cookies: these cookies remain in your browser during your browser session only, i.e. until you leave the website.
Persistent cookies:these cookies remain in your browser for a set period of time after the browser session expires (unless you delete them in advance).
First-party cookies:these cookies are created by us, that is the domain you are visiting (i.e. the website displayed in the URL window).
Third-party cookies:these cookies are created by domains other than the one you are visiting at the time.
When you first visit our website you will see our Cookie Declaration where you can see all the cookies. You can change or withdraw your consent at any time (see "Cookie Consent" below in footer).
If you have any questions regarding this Policy, you may reach our Data Protection Officer at dpo@gupshup.io
Added below language support for WhatsApp,
Bot developers for Line: With the release of Line Messaging API, all BOT API Trial Accounts are scheduled to be deleted. Please republish your bot according to new Line implementation, mentioned under Publish tab in My Bots section.
New tool for non-developers- Our Flow Bot Builder helps users create their bot messaging flow with a graphical editor.
API.ai tool is now available for developing your NLP/AI bot.
Gupshup Enterprise APIs (SMS,Voice and Email) are now available directly in the APIs section.
New channels added for publishing bots- Smooch.io and your website as a web widget.
Now you can access our services including the bot builder tool using your Facebook login credentials.
Now you can delete the dummy bots created for testing from the My Bots Dashboard.
You can now access Bot specific data from your Dashboard itself.
Introducing a hassle free bot development experience for users to instantly create bots using our pre-defined restaurant templates. Check out our blog to know more.
We are removing few redundant parameters, that were being sent when a callback happens to your bot (i.e. inbound message comes to your bot).
Following is the list of parameters.
However, we will continue to send following parameters. If you are using any of the deprecated parameters, we request you to use these alternatives.
You are requested to make a note of this and do the necessary changes immediately to your bot code to keep it working. Should you need any help, please feel free to send an email to devsupport@gupshup.io