Have you ever written an FAQ or document on a website but still get people asking you the same questions? When it comes to users or customers, there’s no such thing as a bad question, but answering the same questions can become tedious. Have you ever wanted to create a bot that answers all these questions so you don’t personally have to?
If you’re not familiar with StdLib yet, you’re in for a treat! We’re a serverless API development and publishing platform that can help you build and ship custom logic in record time.
- 1x Command Line Terminal With Node.js Installed
- 6x Minutes (or 360x Seconds)
- A US Cell Phone Number
After that you will need to install the StdLib CLI by opening up a terminal and running:
$ npm install lib.cli -g
Next, we’re going to create a workspace for your StdLib functions. Create a new folder and initialize it with the following commands:
$ mkdir stdlib-workspace
$ cd stdlib-workspace
$ lib init
Use the credentials you created earlier.
We will use the MessageBird API to send and receive text messages. StdLib makes it really easy for you to initialize a number, send and receive messages.
First, navigate to the messagebird.numbers service page on StdLib and accept the terms of service.
After you’ve done that, return to your terminal and run:
$ lib messagebird.numbers.available --country <CA or US>
You should see a list of available, unclaimed telephone numbers. Choose one from the list, then run:
$ lib messagebird.numbers.initialize --number <chosen phone number>
You can then test your number by sending a text message with the
Run the following command from your terminal:
$ lib messagebird.sms.create \
--recipient <your personal phone number> \
--body Hello from StdLib!
And you should receive a text message from the number you’ve just claimed!
QnA Maker is a free Microsoft service that allows you to build, train and publish a simple question and answer bot based on FAQ URLs, structured documents or editorial content in minutes.
You will be given the opportunity to review the knowledge base you have created.
You can even delete QnA pairs or add an alternative phrasing of the same question. This will be useful for questions that do not match the existing knowledge base.
You can also test and train your bot.
Once you are done hit “Publish” to publish your bot.
You will then be provided with a sample HTTP request. Keep this page open as you will need this information later on.
Now that you have trained your QnA service you will need a handler that will respond to incoming questions sent to your MessageBird number. Thankfully we have a template that you can start with.
From your main StdLib workspace in your terminal, fork the starter sourcecode by running:
$ lib create -s @messagebird/messagehub
You’ll be prompted to give your service a name (e.g.
QAService) and then hit enter to create your service directory.
In order to interact with the QnAMaker.ai knowledge base we created, we will need to make a HTTP POST request. To do that we will use a common npm package — axios. We will need to install this package in our sourcecode.
In your service directory where your source code is e.g
$ npm install --save axios
This will modify your
package.json file and install the npm package axios into your service directory.
Assuming you are in the service directory run
$ code . or something similar to open the directory in your favorite text editor.
Your handler service contains three endpoints within the
main.js, the main endpoint of your handler. This function will receive events triggered by incoming SMS messages to your MessageBird number and will call other handlers appropriately
messaging/more.js, a handler for incoming messages that contain the word “more” as their sole contents
messaging/notfound.js, a “not found” handler. If the incoming message can not be mapped to a named function (like
more), this handler will be triggered
For this application we will be modifying
notfound.js as most if not all questions will trigger this handler.
Copy the code below and replace the existing code in
In line 17 and 18 you will need to fill in the
key from the Sample HTTP request that was provided to you by the QnAMaker.ai service.
uri is the string that comes directly after
POST and the
key is the string that comes after
Alternatively you can also add
key as environment variables in our
Due to anti-spam regulations, MessageBird’s API prevents you from sending messages with URLs in them. Please contact us about having this restriction removed at email@example.com.
The last bit of code we will need to modify is adding our
STDLIBTOKEN into our
First, fetch your StdLib Token from the StdLib Dashboard. You’ll be asked to log in again — once you’ve done so, click on Library Tokens on the left and you’ll see this page:
This is your StdLib auth token, click Show token to see its value and copy and paste it to your
env.json file under
When you’re ready, run the following command from your service directory:
$ lib up dev
The final step is setting the service you just deployed as a handler. Run the following command from your command line:
$ lib messagebird.handlers.sms.set \
--number <your previously claimed phone number> \
You can see a list of your claimed numbers by running
$ lib messagebird.numbers.list if you need to see your claimed number again.
To test your amazing new FAQ Bot simply text your claimed MessageBird Number.
For example, I created a Concierge Bot for the upcoming 2018 Grace Hopper Celebration.
That’s it! Your FAQ SMS Bot is live! Thanks for reading, and we hope we’ve been helpful showing you how easy it is to create an FAQ SMS Bot using Standard Library, MessageBird and QnA Maker.
StdLib is your new API development solution, built atop serverless architecture for fast deployments and infinite scalability. To stay informed of the latest platform updates, please follow us on Twitter, @StdLibHQ, or if you’re interested in joining the team — we’re hiring! Shoot us an e-mail or resume to firstname.lastname@example.org.