hbot-con
v1.1.0
Published
Hbot module connection
Readme
Install :
$> npm install git+ssh://[email protected]/hbot-buildabot/hbot-con.gitSimple start :
var hbot = require('hbot-con');
/**
* hbot.MODULES.XXXXX
* XXXXX can be
* - TUNNEL
* - FLOW
* - LOGIC
* - INTENT
* - CMS
*/
//Initial hbot connect (xxxx123321 is module id)
hbot.init(hbot.MODULES.TUNNEL, "xxxx123321");
//Set onMessage listener
hbot.setOnMessageListener(function(msgObj) {
console.log('Got new message %s from %s (%s)', msgObj.msg, msgObj.fromModuleName, msgObj.fromModuleId);
});
//Create message object for send
var msgObj = new Message({
msg:'Hello',
msg_id:'1231234',
msg_type:'text',
attr: {
first_name:'FIRST',
last_name:'LAST'
}
});
//Send message to other module (xxxx123321 is target module id)
hbot.sendMessage(msgObj, hbot.MODULES.FLOW, "xxxx123321");
//Start hbot service
hbot.start();Disable RabbitMQ for testing :
hbot.start(true);Specific RabbitMQ Server :
hbot.init(hbot.MODULES.TUNNEL, "xxxx123321", '127.0.0.1');New Message :
var msgObj = new Message();
msgObj.msg = 'Hello';
msgObj.msg_id = '1231234';
msgObj.msg_type = 'text';
msgObj.attr = {
first_name:'FIRST',
last_name:'LAST'
};Or :
var msgObj = new Message({
msg:'Hello',
msg_id:'1231234',
msg_type:'text',
attr: {
first_name:'FIRST',
last_name:'LAST'
}
});Message Format:
Text Message :
{
'msg_id':'123456',
'msg_type':'text',
'msg':'this is message',
'fromModuleName':'{FROM MODULE NAME}',
'fromModuleId':'{FROM MODULE ID}'
'attr': {
"first_name":"{FIRST_NAME}",
"last_name":"{LAST_NAME}",
"email":"{EMAIL}",
"conversation_state":"{STATE}"
...
}
}Audio / Video / Image Message:
{
'msg_id':'123456',
'msg_type':'audio' / 'video' / 'image',
'msg':'http://file.com/path/to/file.mp4',
'fromModuleName':'{FROM MODULE NAME}',
'fromModuleId':'{FROM MODULE ID}'
'attr': {
"first_name":"{FIRST_NAME}",
"last_name":"{LAST_NAME}",
"email":"{EMAIL}",
"conversation_state":"{STATE}"
...
}
}Carousel Message:
{
'msg_id':'123456',
'msg_type':'carousel',
'msg':[
{
'title': 'TITLE 1',
'image_url': 'IMAGE 1',
'subtitle': 'SUBTITLE 1',
'buttons': [
{
'type':'web_url',
'url':'http://url1.com/xxx/yyy',
'title': 'BUTTON 1 TITLE'
},
{
'type':'web_url',
'url':'http://url2.com/xxx/yyy',
'title': 'BUTTON 2 TITLE'
}
]
},
{
'title': 'TITLE 2',
'image_url': 'IMAGE 2',
'subtitle': 'SUBTITLE 2',
'buttons': [
{
"type": "show_block",
"block_name": "{CHATFUEL BLOCK NAME}",
"title": "BUTTON 1 TITLE"
},
{
"type": "show_block",
"block_names": ["{CHATFUEL BLOCK 1 NAME}", "{CHATFUEL BLOCK 2 NAME}"],
"title": "BUTTON 2 TITLE"
}
]
},
],
'fromModuleName':'{FROM MODULE NAME}',
'fromModuleId':'{FROM MODULE ID}'
'attr': {
"first_name":"{FIRST_NAME}",
"last_name":"{LAST_NAME}",
"email":"{EMAIL}",
"conversation_state":"{STATE}"
...
}
}Json Message (Use for chatfuel interface api) :
{
'msg_id': '123456',
'msg_type': 'json',
'msg': {
'fb_id':'xxsxcsdfwef',
'fb_first_name':'ssssssss'
...
},
'fromModuleName':'tunnel',
'fromModuleId':'TUNNEL0'
'attr': {
'first_name': 'Fool',
'last_name': 'Bar',
'conversation_state':'{STATE}'
}
}