Chatbots and Internet of Things with thethings.iO IoT platform

Most of the IoT projects where thethings.iO works today use a mobile application as a user interface. Some of these users are different actors of the project, can go from final clients to technicians or managers. That means that some of them don’t need any specific user experience, they just need an interface to interact with the connected devices. Ask questions, such as last values, change configurations, and offer a kind of a “bidirectional” communication.

At that moment, clients have different choices, build their own mobile application for each of the actors of the project, or just start prototyping these applications with a chatbot. And actually at thethings.iO we love chatbots. We think it’s a great tool to prototype apps and to get first insights from the actors of the project interacting with the connected things.

For that situation, we have created a chatbot framework with thethings.iO Cloud Code to enable our clients to use chatbot technology, such as Telegram and others coming soon, as the interface to talk with the connected things. And the results are great!

Telegram chatbot connected with thethings.iO

Telegram is an instant messaging platform that provides a lot of flexibility to developers. Telegram offers an easy way to create chatbots with an API integration. As we did in the past with Twilio, Mailchimp and others, we have integrated automagically Telegram with thethings.iO Cloud Code.

The Telegram + thethings.iO Cloud Code service let you send a Telegram message to a Telegram account using a Telegram Bot from thethings.iO. On of the most important requirements is that the user have to acknowledge, starting a conversation, to received a message from the bot. In some cases is not allowed to push information without this acknowledgement.

We have created a demo, so you can play with it on Cloud Code. So download the Telegram Instant Messaging application and search for the thethings.iO bot.

Get into the bot and click the button START on the bottom or just write /start.

At that point the thethings.iO Bot will send you a welcome message with a chat_id.

Every conversation between a user and a bot have a chat_id, it’s important that you can manage these chat_ids from Cloud Code in case you want to have more than one user. For this demo, we are only going to have one user. So we are going to copy and paste this chat_id into the Cloud Code code (Trigger).


function main(params, callback){
var chat_id = 12345;
var message = 'Hello world';

var options = {chat_id : chat_id, text: message};

telegram.sendMessage(options, function(err, result)
{
if(err) return callback(err)
callback(null, result)
})
}

In that case, every time we execute this Trigger we will send to the user a Hello World message.

That’s great right?!

In the previous example you are using thethings.iO Telegram bot. In case that you are building your own bot, find here the code to introduce your own custom_bot ID.


var chat_id = 12345;
var message = 'Hello world'
var custom_bot = 'abcdefghijklm'
var options = {chat_id : chat_id, text: message, custom_bot: custom_bot};

This is the first part of this tutorial. In next tutorials about chatbots and Internet of Things we will showcase how to manage multiple chat_ids of different users from the project into one thethings.iO Cloud Code function, among other features. And of course, expect other chatbot integrations. Anyway if you have a chatbot technology and you think it could be interesting to integrate it with thethings.iO, feel free to contact us!

Enjoy thethings.iO IoT Platform experience! Let’s stay connected