[Node.js SDK][Connector] Two custom connectors cross over when sending
Bot Info
- SDK Platform: Node.js
- SDK Version: 3.14.1
- Active Channels: Not a problem with existing channels offered in ABS
- Deployment Environment: Azure Bot Service + Heroku
Issue Description
I have 2 custom connectors, line and cisco. When I receive a message in line, the message then crosses over to the send function of cisco.
According to the documentation, the function has to be named send. So is there a way to differentiate from two sends?
Code Example
const express = require('express'),
builder = require('botbuilder'),
lineConnector = require("botbuilder-line")({
channelSecret: process.env.line2,
channelAccessToken: process.env.line3,
debug: true
}),
cisco = require("botbuilder-ciscospark")({
token: process.env.SPARK_TOKEN,
path: "/cisco",
port: process.env.PORT,
name: "[email protected]",
debug: true
});
// Sessions...
var server = express();
server.use(bodyParser.json({type: "*/*"}));
server.post('/api/messages', connector.listen());
server.post('/line', lineConnector.listen);
server.post('/cisco', cisco.hears);
server.listen(process.env.PORT || 5000, function () {
console.log('%s listening to %s', server.name, server.url);
});
For full scripts...
Reproduction Steps
- Send a message on
line.
Expected Behavior
A response from line.
Actual Results
The message is being processed in the send function of cisco, which cannot recognize line messages.
@austinhuang0131 can you provide a trace log of when your bot tries to reply to a LINE message?
- Active Channels: Not a problem with existing channels offered in ABS
Does this mean you're not using the channels provided from ABS at all, or you're not seeing any problems with routing messages when trying to reply to an official channel?
There is no problem with routing messages via official channels.
Warning: Long logs
2018-05-07T18:12:44.886389+00:00 heroku[router]: at=info method=POST path="/line" host=censored.herokuapp.com request_id=5bb665fe-8df3-410d-aefa-b40a4e8045cd fwd="censored" dyno=web.1 connect=0ms service=49ms status=200 bytes=200 protocol=https
2018-05-07T18:12:44.885445+00:00 app[web.1]: BotBuilder-Line > Messages received { events:
2018-05-07T18:12:44.885483+00:00 app[web.1]: [ { type: 'message',
2018-05-07T18:12:44.885488+00:00 app[web.1]: replyToken: 'censored',
2018-05-07T18:12:44.885490+00:00 app[web.1]: source: [Object],
2018-05-07T18:12:44.885491+00:00 app[web.1]: timestamp: 1525716764093,
2018-05-07T18:12:44.885493+00:00 app[web.1]: message: [Object] } ] }
2018-05-07T18:12:44.924946+00:00 app[web.1]: BotBuilder-Line > Message processed { timestamp: 1525716764093,
2018-05-07T18:12:44.924950+00:00 app[web.1]: source: 'line',
2018-05-07T18:12:44.924951+00:00 app[web.1]: replyToken: 'censored',
2018-05-07T18:12:44.924953+00:00 app[web.1]: entities: [],
2018-05-07T18:12:44.924955+00:00 app[web.1]: address:
2018-05-07T18:12:44.924957+00:00 app[web.1]: { bot: { name: 'placeholder', id: 'placeholder' },
2018-05-07T18:12:44.924958+00:00 app[web.1]: user:
2018-05-07T18:12:44.924960+00:00 app[web.1]: { name: 'censored',
2018-05-07T18:12:44.924962+00:00 app[web.1]: id: 'U74e92ce16051d4b129c5f866e230f58b' },
2018-05-07T18:12:44.924963+00:00 app[web.1]: channelId: 'line',
2018-05-07T18:12:44.924965+00:00 app[web.1]: channelName: 'line',
2018-05-07T18:12:44.924966+00:00 app[web.1]: msg:
2018-05-07T18:12:44.924968+00:00 app[web.1]: { type: 'message',
2018-05-07T18:12:44.924969+00:00 app[web.1]: replyToken: 'censored',
2018-05-07T18:12:44.924971+00:00 app[web.1]: source: [Object],
2018-05-07T18:12:44.924973+00:00 app[web.1]: timestamp: 1525716764093,
2018-05-07T18:12:44.924975+00:00 app[web.1]: message: [Object] },
2018-05-07T18:12:44.924976+00:00 app[web.1]: conversation: { id: '1', isGroup: false } },
2018-05-07T18:12:44.924978+00:00 app[web.1]: text: 'test',
2018-05-07T18:12:44.924980+00:00 app[web.1]: agent: 'botbuilder',
2018-05-07T18:12:44.924981+00:00 app[web.1]: type: 'message',
2018-05-07T18:12:44.924983+00:00 app[web.1]: user:
2018-05-07T18:12:44.924985+00:00 app[web.1]: { name: 'censored',
2018-05-07T18:12:44.924986+00:00 app[web.1]: id: 'U74e92ce16051d4b129c5f866e230f58b' } }
2018-05-07T18:12:45.494831+00:00 app[web.1]: Unhandled Rejection at: Promise {
2018-05-07T18:12:45.494868+00:00 app[web.1]: <rejected> 'BotBuilder-CiscoSpark > Ignoring messages for other platforms...[{"type":"message","agent":"botbuilder","source":"line","address":{"bot":{"name":"placeholder","id":"placeholder"},"user":{"name":"censored","id":"U74e92ce16051d4b129c5f866e230f58b"},"channelId":"line","channelName":"line","msg":{"type":"message","replyToken":"censored","source":{"userId":"U74e92ce16051d4b129c5f866e230f58b","type":"user"},"timestamp":1525716764093,"message":{"type":"text","id":"7920081599139","text":"test"}},"conversation":{"id":"1","isGroup":false}},"text":"It seems like you\'re confused. Maybe try typing \\"help\\". Alternatively, type \\"start\\" to start the bot up."}]' } reason: BotBuilder-CiscoSpark > Ignoring messages for other platforms...[{"type":"message","agent":"botbuilder","source":"line","address":{"bot":{"name":"placeholder","id":"placeholder"},"user":{"name":"censored","id":"U74e92ce16051d4b129c5f866e230f58b"},"channelId":"line","channelName":"line","msg":{"type":"message","replyToken":"censored","source":{"userId":"U74e92ce16051d4b129c5f866e230f58b","type":"user"},"timestamp":1525716764093,"message":{"type":"text","id":"7920081599139","text":"test"}},"conversation":{"id":"1","isGroup":false}},"text":"It seems like you're confused. Maybe try typing \"help\". Alternatively, type \"start\" to start the bot up."}]
Apparently botbuilder does not recognize <function>.prototype.send.
ALSO 2 WEEKS WITHOUT RESPONSE
Hi @austinhuang0131 , more than one year ago I had a requirement like yours, and got it working, and published it as opensource. https://github.com/jseijas/flow-bot/blob/master/src/connector/flow-multi-connector.js
Basically what I have is a connector that keeps a list of other connectors, and is able to redirect the events based on the name of the channel, that is in message.address.channelId. This is compatible with the Microsoft Chatbot Connector, but you can add new connector with the condition of following the structure needed by Microsoft Bot Framework. To help on that, there is a base class FlowConnector that you can inherit from (you have an example in the FlowSlackConnector).
Example of use:
const facebookconnector = new FlowFacebookConnector({
verifyToken: '<FACEBOOK_WEBHOOK_VERIFY_TOKEN>',
accessToken: '<FACEBOOK_ACCESS_TOKEN>',
appSecret: '<FACEBOOK_APP_SECRET>'
});
const restconnector = new FlowRestConnector({});
const connector = new FlowMultiConnector({});
connector.addConnector('emulator', restconnector);
connector.addConnector('facebook', facebookconnector);
bot = new builder.UniversalBot(connector);
As @jseijas indicated the proper approach would be to roll your own parent connector that handles the dispatching of activities/messages/events across different channels/connectors. To my knowledge the BotBuilder SDK doesn't have built in support for using multiple connectors at once.