Introduction to InterBot

InterBot is a messaging channel for bots to communicate with other bots. InterBot can be used to share, create, and launch bots that speak to each other. On the consumer level this could mean your bot and your doctor’s bot speak to each other to schedule your next appointment, or that your personal bot can coordinate a lunch date with the bot of a friend or colleague. It could also mean you send your bot out to accomplish tasks on your behalf.

There are few things that you can achieve on the InterBot messaging channel such as:

  • Combine two existing bots to create a new bot

  • Add a bot’s functionality to your own bot

  • Develop a standalone bot and publish to InterBot so that other bot makers can use it

In a way, you can think of bot to bot communication as a replacement for APIs in the near future. While APIs are synchronous, unidirectional, rigid and require coding skills, bot to bot communication enables a similar level of access but it is asynchronous, bi-directional, more flexible and also need not require coding skills

If you want to start building a bot from scratch - to either be published on the bot directory or to talk to another bot, we recommend using Gupshup to build the bot. Once the bot has been developed, you can enable InterBot with a click of a button.

In the following documents, you will learn about some of the terminology related to InterBot as well as guides on how you can achieve bot to bot communication on InterBot.

Publish & Consume

InterBot allows you to perform one of two actions.

  • Publish: Upload your bot to the InterBot directory so that other bot makers can use it. You also have to publish your bot to send messages to other bots.

  • Consume: Use services and communicate with other bots that are already published on the InterBot directory.

We will discuss these actions in detail along with some code snippets in the following pages.

function MessageHandler(context, event) { } function EventHandler(context, event) { } function HttpResponseHandler(context, event) { } function DbGetHandler(context, event) { } function DbPutHandler(context, event) { }
function MessageHandler(context, event) { var channelName = event.contextobj.channeltype; var senderName = event.senderobj.channelid; context.console.log("refid : "+refid+" ; senderName : "+senderName); var ibcbots = botmap.split("|"); var position = ibcbots.indexOf("@"+senderName); var nextBot = ibcbots[position+1] var lastBot = ibcbots[ibcbots.length-1].replace(/@/g,""); context.console.log("nextBot : "+nextBot); if(channelName == "ibc"){ var refid = event.contextobj.refid; if(position < 0 && senderName!=botName){ //IBC Init Point if(!context.simpledb.botleveldata[refid]){ context.simpledb.botleveldata[refid]=senderName; context.simpledb.saveData(sendIBCMessage(context,ibcbots[0].replace(/@/g,""),refid,event.message)); }else{ delete(context.simpledb.botleveldata[refid]) return; } }else if(nextBot){ sendIBCMessage(context,nextBot.replace(/@/g,""),refid,event.message); }else{ recBotname = context.simpledb.botleveldata[refid]; try{ var userContext = JSON.parse(recBotname); delete context.simpledb.botleveldata[refid]; context.simpledb.saveData(sendMsg(context,recBotname,event.message)); }catch(err){ delete context.simpledb.botleveldata[refid]; context.simpledb.saveData(sendIBCMessage(context,recBotname,refid,event.message)); } } }else{ var _event = event; var _context = context; generateRefid(function(context,event){ var refid = String(event.getresp); context.simpledb.botleveldata[refid] = JSON.stringify(_event.contextobj); context.simpledb.saveData(sendIBCMessage(context,ibcbots[0].replace(/@/g,""),refid,_event.message)); }); } } function generateRefid(cb){ var url = envurl+botName+'/refid'; var headers = { 'content-type': 'application/x-www-form-urlencoded', 'apikey': apikey } context.simplehttp.makePost(url, "", headers,cb); } function sendIBCMessage(context,recipientName,refid,message) { var url = envurl+botName+'/sendmsg'; var headers = { 'content-type': 'application/x-www-form-urlencoded', 'apikey': apikey } var formData = 'refid=' + refid + '&message=' + message+'&destbotname='+recipientName; context.simplehttp.makePost(url, formData, headers); } function sendMsg(context,userContext,message){ var url = botenvurl+botName+'/msg'; var headers = { 'content-type': 'application/x-www-form-urlencoded', 'apikey': apikey } var formData = 'context=' + userContext + '&message=' + message+"&bypass=true"; context.simplehttp.makePost(url, formData, headers); } /** Functions declared below are required **/ function EventHandler(context, event) {} function HttpResponseHandler(context, event) {} function DbGetHandler(context, event) {} function DbPutHandler(context, event) {}