Drawers Bot

Drawers chat is powered by Mqtt, a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

We are using eclipse paho client to interact with the backend. In this blog i will walkthrough for writing simple Echo bot in java.

First of all, you need to add paho client and drawers sdk to your dependencies.

Add jitpack to your repositories inside project in pom.xml as drawers-java-sdk package is obtained from Github — link.

Create Bot instance as below:

Awesome, you have a bot up and running and connected to server. Will discuss later how to obtain clientId and password

Now, you need to subscribe to receive messages as soon as bot is connected.

Now you have received message, inside receiveMessage block, just process it and reply as below.

And you are done, the signature of MqttChat is as below:

Find the complete code at Github.

Now, to obtain client id and password:

Login to https://broker.sandwitch.in/botAdmin (only firefox supported)

Go to add bot and add bot details.

Once bot created you will receive credentials and bot virtual number as below

You can save bot’s virtual number to your phone and communicate with the bot. You can also sync the bot to the search engine.

We will cover complex bots in further stories.