Bot Dialog Action button issue node.js - dialog

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.

Related

how to get the result from the people-picker when the user clicks on the button

Use the bot framework composer to display the adaptive card "people-picker" in my chatbot in Teams.
When I select a person from the people-picker and click on the Check button i get the message:
Your response was send to the app
How can i capture that response in a string variable in the Bot Framework Composer enter image description here?
Greetings,

Can I send Hero cards to whats app by using Twilio

I have chat bot, I build it with bot framework nodejs SDK I integrate this chat bot to whatsapp and I want to display some buttons in the whatsapp chat,
So is there any one found a solution for this problem pleas help me
Note: I try to send a hero card but I run to problem
Error: TwilioWhatsAppAdapter.parseActivity():
An activity text or attachment with contentUrl must be specified.
I don't know how bot framework attempts to send WhatsApp messages with buttons, but I doubt it fits with the way Twilio wants to send them.
Currently, to send a message with buttons, you need to register and use a template message. When you send the text of a message that matches one of your templates, then Twilio will deliver the entire template with buttons as well.
For the future, look out for the Twilio Content API which will streamline templates, buttons and other rich messages across platforms.
It looks like you are using the TwilioWhatsAppAdapter from the botbuilder-community-js repo.
Looking at the adapter's code, it doesn't appear to be configured to handle any card other than a 'signin' card (see here). If you don't mind doing a little leg work on this, I don't see why you couldn't fork this repo and build in functionality that supports a hero card similar to the signin implementation.
I imagine it would look something like this:
case 'application/vnd.microsoft.card.hero':
// eslint-disable-next-line no-case-declarations
const hero = attachment.content;
message.body = `${ hero.text }\n\n`;
message.body += (hero.buttons[0].title ? `*${ hero.buttons[0].title }*\n` : '');
message.body += hero.buttons[0].value;
break;
The above may need a little massaging but it wouldn't be far off from this. Then, you just need to build the library for use.

Triggering telegram bot command on user input

I have a situation where I need to run a telegram command when user sends some message to the bot to open a menu from telegraf-inline-menu.
As this library offers a functionality to open that menu on some command like menu.setCommand('start') I thought it would be appropriate to just trigger command on bot.hears().
In pseudo code
menuSetcommand('/test')
bot.hears(someRegex, ctx => {
triggerCommand('/test')
})
If this is not possible, some tips and directions for research are highly appreciated!

Chat bot-Can I display html content using node.js in Microsoft bot framework & bot builder

I'm developing a chatbot on azure using node.js. It's a data visualization bot which generates chart in html format using d3 library and display to user.
It seems that Microsoft bot builder doesn't support html format. But I have looked through this link:
https://blog.botframework.com/2017/09/07/html-not-supported-web-chat/
It says that there is a way to enable html content:
"If HTML rendering in Web Chat is a critical feature for your applications, you can clone or fork a copy of the Web Chat source code from GitHub, and enable it (on your own custom Web Chat client)."
I tried to clone the file and changed ‘html : false’ to ‘html : true’. But it's not working.
Can anyone tell me what I can do? Really appreciate it!!!
Depending on what data you are attempting to visualize, you might be able to use a service like Google Image Charts: https://developers.google.com/chart/image/docs/chart_playground
Using this service, with the following code:
// attach the card to the reply message
var msg = new builder.Message(session).addAttachment(createHeroCard(session));
session.send(msg);
function createHeroCard(session) {
return new builder.HeroCard(session)
.title('Months with Numbers Bar Chart')
.subtitle('Using a Chart as Image service...')
.text('Build and connect intelligent bots that have charts rendered as images.')
.images([
builder.CardImage.create(session, 'http://chart.googleapis.com/chart?cht=bvg&chs=250x150&chd=s:Monkeys&chxt=x,y&chxl=0:|Jan|Feb|Mar|Apr|May|Jun|Jul')
])
.buttons([
builder.CardAction.openUrl(session, 'https://learn.microsoft.com/bot-framework/', 'Get Started')
]);
}
Produces this hero card:

Bot Framework Event for Postbacks?

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

Resources