Bot Framework Event for Postbacks? - node.js

My question:
I have an adaptive card with a postback button whose value is say "thisIsMyPostback". Now, I want to act on this postback as one would.
The problem is that this postback can also be typed out to reach the same result. In other words, clicking the button and also just messaging my bot "thisIsMyPostback" straight up result in the same thing.
Is there a way to separate a postback message from a 'message_received'? That way a user messaging "thisIsMyPostback" straight up would not result in the same thing as clicking the button.
Thanks!

The Adaptive Cards readme on the BotFramework WebChat GitHub repo GitHub repo states:
The data property of the action may be a string or it may
be an object. A string is passed back to your bot as a Bot Builder SDK
imBack activity, and an object is passed as a postBack activity.
Activities with imBack appear in the chat stream as a user-entered
reply. The postBack activities are not displayed.
"actions": [
{
"type": "Action.Submit",
"title": "Next",
"data": { "postBack": "thisIsMyPostback" }
}
]
If the value of the Activity doesn't have an object, then the user did not click the button.

Is there a way to separate a postback message from a 'message_received'? That way a user messaging "thisIsMyPostback" straight up would not result in the same thing as clicking the button.
No, it's not currently possible, because all messages, user or imBack/postBack, are of type "message" so there's no way to tell the difference unless you put some special text in your postBack and configure a triggerAction to recognize it.
For more information on using trigger actions, see:
https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-global-handlers#trigger-a-help-dialog

Related

How do you call a 3rd party API from inside watson assistant?

Creating a chatbot using IBM's Watson Assistant, and I need to make a determination I'm trying to send the zip code to a third party API that will return the city and state so I know where the client is located so I can (a) know which services are available and (b) have a better idea on how to direct the conversation from there. But I am at a loss as to how to do this.
I can do this from within Python, but trying to code it in a JSON editor doesn't work.
Webhooks are used to do this from inside the Dialog skill in an Assistant.
IBM Watson Assistant webhooks documentation
The docs do not mention it, but the Assistant will POST to the URL with a JSON body containing the parameters you specify as key value pairs. For example if in the Dialog Node the context variable $zipcode equals '99501' and you specify the parameters "key" = zipcode and "value" = "$zipcode".
Then the HTTP post body is
{ "zipcode" : "99501" }
The response from the service is put into another context variable, and this can then be used for other things. For example in the Dialog Node which calls the webhook, in the "Return variable" section put webhook_result_zipcode to put the response into that context variable.
You can also in the dialog node Assistant responds section, return a message which contains some part of the webhook response. For example in the Dialog Node editor
"If assistant recognizes" $webhook_result_zipcode "Respond with" The code is "$webhook_result_zipcode.response.result.sent" This will tell the user the code which is returned deep within the webhook response in response.result.sent in the response body.
You can also click the Cog next to the response, and in the dialog, click ... next to "Assistant responds" and open the context editor. This opens a context editor (at the top of the dialog) which allows setting of another context variable from part of the webhook response. For example under "Then set context" for "Variable" set zipcode and for "Value" set "$webhook_result_zipcode.response.result.sent.zipcode". This will extract a zipcode value from deep within the webhook response and place it in the context variable zipcode.
Of course then you must find a zipcode location service which accepts a HTTP post and looks for the code in the body.

Bot Dialog Action button issue node.js

I am trying to create bot for MS Teams via Microsoft Bot Framework using some examples from the Internet.
I have created user card that has button "See Report"
function userCard(session, connector, name, workingStatus, TeamsID) {
var card = new builder.HeroCard(session)
.title(name)
.subtitle(workingStatus.toString())
.buttons([
builder.CardAction.dialogAction(session, 'userReport', TeamsID, 'See Report')
]);
return card;
}
Card is displayed without any issues. When I press on button it should trigger new dialog
//Begins the userReport dialog if the button on the userCard is pressed
bot.beginDialogAction('userReport', '/userReport');
This functionality works perfect when I test it in Bot Framework Emulator.
In MS Teams instead of triggering userReport dialog it goes to the main dialog (the one that is used when message is sent). So that this button does not work at all.
Could you, please, advise what should be adjusted/added in order to make this button work in MS Teams?
Thanks in advance!
Thank goodness you're just getting started. It looks like you're using Bot Framework V3, which is severely outdated. You should definitely switch to V4.
Teams has it's own additional trickiness. I recommend trying out and combing through each of these samples:
57.teams-conversation-bot
07.using-adaptive-cards
Then read through the Adaptive Cards blog post.
Basically, a response from an Adaptive Card comes back in activity.value, so in onTurn(), you'll want to use an if statement to watch activity.value for the value sent in your Adaptive Card when the user clicks "See Report". Then, use beginDialog or dialog.run(), as appropriate to start your dialog.

Google Dialogflow Quick Replies formatting issues in Telegram

I had create a chatbot using Dialogflow and integrated it with Facebook Messenger & Telegram. I noticed that for the Quick Replies in Telegram (Link 1) appears differently in FB Messenger (Link 2). Is there any way to make it nicer and more presentable in Telegram?
Telegram
Facebook Messenger
This is my Quick Replies settings in Dialogflow.
Dialogflow
in DialogFlow you can indeed (as Marc pointed out) use a Custom Payload for Telegram, here it is an example:
{
"telegram": {
"text": "What would you like help with?",
"reply_markup": {
"inline_keyboard": [
[
{
"text": "Daily News",
"callback_data": "news"
}
],
[
{
"text": "New Features",
"callback_data": "features"
}
]
]
}
}
}
The quick replies appear a buttons you can click (notice the actual response is sent but not displayed within the chat).
All the best!
Beppe
SHORT ANSWER:
That is NOT possible.
DETAILED ANSWER:
Each Channel (Facebook Messenger, Telegram etc.) has its own UI components and its own styling. Those can't be changed as they are rendered/controlled by the channel it self.
What Dialogflow doing is giving you the ability to show these UI components in each channel without making you handle the different implementation needed for each channel.
Dialogflow also gives you the ability to send Custom Payloads where you can send a custom JSON (that should be compatible with the channel you are connected to) That can be used if the channel for example has a UI component that is not yet supported by Dialogflow.
If the channel gives you an option to change a property in the UI components you are using, you could do that using Custom JSON, But still you are always limited to how each channel renders the UI components and what features they provide us

Microsoft Bot Framework attachments for Facebook messenger

Microsoft Bot Framework messages with buttons in Facebook Messenger
My question relates to the question linked aboved. I am writing a bot using node.js that does not use the bot builder sdk. I manually returning a compatible response for the ms bot connector service. This is working fine for a text response, but I wish to return more complicated responses, e.g the buttons/carousel you can return with messenger. Based on the question I linked above, I guessed the format and added the below:
response.attachments = [ { "Title": "Choose One: ", "Actions": [{ "Title": "Postback!", "Message": "Postback from button" }, { "Title": "Postback2!", "Message": "Postback2 from button" }] } ];
The top level title seems to do nothing but the actions render as postback type buttons correctly (they send the Message as the postback content). With messenger you also have the option to return url based buttons, and image urls.
As far as I can tell there is zero documentation on returning attachments using the node bot builder sdk. If there were I'd just write the bot with the sdk in order to obtain the response format.
So my question is, does anyone know how to correctly return both postback and url based buttons to the bot connnector service, including accompanying images, with or without the bot builder sdk?
Update 05/05/2016
So I found the link below and you can see a definition of the attachments property:
http://docs.botframework.com/sdkreference/nodejs/interfaces/_botbuilder_d_.imessage.html
If you follow it to the IAttachment specification, it makes me wonder how/why my code above works at all? As a test of that format I wrote in the following:
var att = {};
att.content = "I am content";
att.contentType = "text/plain";
att.contentUrl = "http://www.google.com";
att.fallbackText = "I am fallback text";
att.text = "I am text";
att.thumbnailUrl = "https://pbs.twimg.com/profile_images/638751551457103872/KN-NzuRl.png";
att.title ="I am title";
att.titleLink = "http://yahoo.com";
Now in slack I get a fairly nice output from this:
However in messenger I get "Service Error:Value cannot be null. Parameter name: source"
I found the info I needed. Not sure if it hadn't been published at the time or whether I was just hunting in the bot builder docs, but it's all detailed fairly well below.
http://docs.botframework.com/connector/message-actions/#navtitle
You have to tweak your message a little for certain integrations, e.g Skype doesn't really seem to support attachments.

Apple Push Notification - View Button Action

I have some problems with my Push Notifications. I can sent them well to my registered Devices. All works fine.
My Questions is: After clicking the VIEW button, the App is launching. At the moment without any content.
How can i add content here? This content should depend on the Push Notification i sent out.
For example: My Push Notification is about NEWS XYZ - then after clicking VIEW i should get more informations about NEWS XYZ
So i think i must get the news from my website. Perhabs with the ID they are posted on my side.
But how to implement this in the App?
I mean with every NEW Push Message, the must be shown the NEW News.
Also it should be possible to read all previous received NEWS in the App in a list, when getting back from NEWS Number 1.
You understand, what i mean?
I dont have any real idea...Would be nice if you can show me code regarding to an example.
Thanks.
This method invokes once you tap on the view button on the push notification,
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateInactive) {
// Application came from the background
// Here you can request for the content
// This has the value of your payload
UILocalNotification *localNotif = (UILocalNotification *) [userInfo objectForKey:#"aps"];
}
else if (application.applicationState == UIApplicationStateActive) {
// Application is in the foreground
}
}

Resources