Hi guys,
instead of triggering the bot via a command / message I want to trigger the Bot via an API to send a Dialog or FormFlow to the User. (c#)
thanks! best chris
We would call that a proactive bot, where an IConnectorClient is instantiated (indirectly through the container) to send messages. I will be checking in an IBotToUser implementation that always uses IConnectorClient to send the messages to the develop branch soon. The oauth sample also does something similar since the callback is driven by an external system.
You're awesome, thanks! I just checked the oauth sample and looking forward to your sample. thanks!
Fyi, this is the "always send direct through IConnectorClient" implementation:
https://github.com/Microsoft/BotBuilder/commit/2409b4d8c7c3d9784eaf9c8d61df380b378d256e
What's the nodejs equivalent to IConnectorClient or IBotToUser? I'm looking to send a new message using the node sdk.
I believe it's just Session.send:
https://github.com/Microsoft/BotBuilder/blob/master/Node/lib/Session.js#L74
@willportnoy Session.send would be perfect in this case, but it's not clear how to instantiate a Session object for a specific conversation outside of a reply to an incoming message.
@Stevenic or @msft-shahins - what is the proper pattern for a proactive bot to instantiate a session in nodejs?
I also tried something like this, which seems like it should start a new conversation
bot.beginDialog({
text: "I'm sending you a proactive message!",
language: "en",
to: { address: "User1", channelId: "emulator" , id: "2c1c7fa3"},
from: { address: "stuffbot", channelId: "emulator", id: "stuffbot" }
},
"/"
);
I don't get any errors, but I also don't get a message sent to me.
@mattdot I managed to get that working! In addition to the format you used, I also specified isBot on both from and to. I'm using the sms channel.
Sorry... I can answer this for the Node side... @mattdod... Your close but you need to actually use a dialog to compose your reply.
bot.add('/notify', function (session) {
session.endDialog("I'm sending you a proactive message!");
});
bot.beginDialog({
to: { address: "User1", channelId: "emulator" , id: "2c1c7fa3"},
from: { address: "stuffbot", channelId: "emulator", id: "stuffbot" }
}, '/notify');
Currently you need to setup a dialog to compose your outgoing message. You then start that dialog with the call to bot.beginDialog(). In many respects your example is a bit more intuitive and we were just talking about adding a bot.send() method that would do what you're suggesting which is to send a proactive message without starting a whole new dialog. The current method is technically more flexible because it lets you start a whole proactive conversation with the user but in the case where you just want to send a message its a little overkill. We'll add that to the todo list.
So I figured out that the equivalent to IConnectorClient is actually in the 'botconnector' module. (as documented here http://docs.botframework.com/connector/libraries/node/#navtitle ). Sorry if I missed it, but is the code for botconnector on github somewhere?
Hi guys,
I think the main question is more than answered and even node has a sample. Thanks Will for the commit.
@mattdot The code is only on npm because it's auto-generated from a Swagger file. It's just a simple wrapper around the REST API for the connector.
@willportnoy do you have a sample of using your piece of code? I checked the oauth sample, but can't mix it both together.. sorry..
hey guys,
do somebody has an example of starting a FormFlow with a proactive bot? I'm struggeling to get it working with the code above. Anybody can help?
thanks, best chris
Program.Interactive is an example of a proactive bot:
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/FormTest/Program.cs
hi guys, @bloudermilk @Stevenic - on your solutions - from where do you get the id value? i'm looking for a very similar solution, at the end of my waterfall to start a dialog on another channel, but can't get it to work (can be anything like sms, email, facebook).
thanks!
@bogdanfer you usually save the recipient id from previous conversations with that user.
You may want to open an issue dedicated to your question.
https://docs.botframework.com/en-us/technical-faq/#how-can-i-get-access-to-the-user-id is related
In the latest api version, all you need to do is save the address from any past conversation:
// Inside some dialog
var savedAddress = session.message.address;
And then set it on any message to target it to same conversation, like so:
someAsyncProcess().then(function () {
var msg = new builder.Message()
.text('This is a Proactive message')
.address(savedAddress);
bot.send(msg);
});
Faced this issue during a recent hackathon and the solution in Node using LUIS as the AI back-end, was to mock a message that would trigger the intended dialog and take it from there.
It is a workaround but we could not find an official way to do this in Node:
var connector = /* connector init */;
var bot = new builder.UniversalBot(connector);
var dialog = new builder.IntentDialog({/* options & recognizers});
var savedAddress = /* load this from a previous message's session.message.address */;
/* ... */
/* Dialog for /initiateContact, called from below Intent matcher */
bot.dialog('/initiateContact', [
(session, args, next) => {
session.send('First message that user sees.');
next();
},
() => {/* ... */}
]);
/* Configure an Intent named InitiateContact activated by an Utterance 'Initiate Contact' */
dialog.matches('InitiateContact', (session) => {
// call Dialog /initiateContact
session.beginDialog('/initiateContact');
});
/* Text field should be the Utterance that triggers the InitiateContact Intent */
var msgTrigger = new builder.Message()
.text('Inititate Contact')
.address(savedAddress);
// mock the receiving of the message that triggers intent InitiateContact
bot.receive(msgTrigger.toMessage());
We have this feature in our bot @Wingify -> https://github.com/wingify/heybot Checkout api.js if it helps.
Hi @willportnoy. Thanks for the update to the SDK which makes this possible. Could you kindly indicate a sample use of the AlwaysSendDirect_BotToUser class?
@adekola Stack Overflow might be a more appropriate forum for asking general questions - in this case, we use AlwaysSendDirect_BotToUser as the default service for outgoing messages to the user from the bot.
I found a good snippet on stackoverflow.
// Send welcome when conversation with bot is started, by initiating the root dialog
bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.beginDialog(message.address, '/');
}
});
}
});
Proactive bot example:
https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/core-proactiveMessages
This issue is closed. If you have a question or problem, please open a new issue here: https://github.com/microsoft/botbuilder/issues/new
Most helpful comment
I found a good snippet on stackoverflow.
(https://stackoverflow.com/questions/43048088/microsoft-bot-framework-sending-message-on-connect#answer-43050305)