Create an SMS bot with ClickSend and API Chatbot

Abby Updated by Abby

In this article we'll show you how you can build an SMS bot using Landbot's API chatbots and communicate with users via SMS

Our chatbot will be very simple, but it can be as complex as you'd like; integrating with chatGPT or anything else you can connect to via REST API

Here are the tools we'll be using:

  • Landbot - API chatbot
  • ClickSend
  • Amazon Web Service - Lambda Functions

The builder

Our builder in this example is very simple, but it can be as complex as you'd like it to be

This isn't the only step in Landbot, we'll also need to create a Hook, we'll do that at the end

ClickSend

You will need a number registered in ClickSend for this workaround

You will also need to generate an API key, which you can do here

AWS Lambda

You will need an AWS account, which you can create here

Once you have your account you will need to create a Lambda function

You will keep all of the default settings, with Node.JS selected

Next you will paste the following code, replacing the first XXXX with your Landbot API key

You will replace the second XXX with your ClickSend credentials

const axios = require('axios');
exports.handler = (event, context, callback) => {
let jsonData = event;
if (!jsonData.body.includes('messages')) {
let data1 = jsonData.body; let buff = new Buffer(data1, 'base64');
let text = buff.toString('ascii');
let decodedJSON = JSON.parse('{"' + text.replace(/&/g, '","').replace(/=/g,'":"') + '"}',
function(key, value) { return key===""?value:decodeURIComponent(value) });
let message = decodedJSON.message
let from = decodedJSON.from
const sendResponse = axios.post(`https://chat.landbot.io/v1/send/${from}/`,
{ "message": { "type": "text", "message": message } }, { headers: { Authorization: 'Token XXXXXXX'} })

}
else {
let data2 = JSON.parse(jsonData.body);
let message = data2.messages[0].message
let token = data2.customer.token
try { const sendResponse = axios.post(`https://rest.clicksend.com/v3/sms/send`, { "messages": [ { "body": message, "to": token } ] }, { headers: { "Authorization": "Basic XXXXXXXX==", "Content-Type": "application/json" } });

}
catch (err) { console.log(err) } }
return { statusCode: 200

Next you will press Deploy

Next we will go to configuration and create a function url:

Please note if you select AWS_IAM you will need the help of a developer to set it up

Now we can copy the function url and use it for our Hooks

The Hooks

Let's start with Landbot, you will need to go to your API chat integrations section and select 'Create a new channel' if you don't already have one

Here's where you'll add the AWS URL

Lastly, you'll connect the API chatbot to this channel

Here's where you'll need to go in your ClickSend dashboard

That's it! You should publish all changes and you'll have an SMS bot

Please note this is not a native Landbot feature and support will be limited for this, it's advised to get support from a developer

How did we do?

APIs

reply from Slack: How to create an integration to allow agents reply WhatsApp users from Slack (with Node JS)

Contact