Unable to get telegram inline buttons to work - node.js

I was working with MS Bot framework and wanted to display some inline buttons on telegram after going through the documentation and some related questions i wrote the following but after session.send(temp) I'm not getting any buttons on the channel.
var temp = {
"type": "Message",
"from": { "channelID":"telegram", "address": session.message.from.id},
"to": { "channelID":"telegram", "address": session.message.to.id},
"conversationId": session.message.conversationId,
"channelData": {
"method": "editMessageReplyMarkup",
"parameters": {
"message_id": session.message.id,
"reply_markup": {
"inline_keyboard": [
[{"text": "Show me more options", "callback_data": "next"}],
[{"text": "Start a new search", "callback_data": "quit"}]
]
}
}
}
};
session.send(temp);

Buttons are supported natively in BotFramework so you don't need to use ChannelData. (See Docs)
"buttons":
[
{
"type": "imBack",
"title": "Show me more options",
"value": "next"
},
{
"type": "imBack",
"title": "Start a new search",
"value": "quit"
}
]

If you did want to achieve this through channelData, you must stringify the value of the reply_markup field, e.g.:
"reply_markup": JSON.stringify({
"inline_keyboard": [
[{"text": "Show me more options", "callback_data": "next"}],
[{"text": "Start a new search", "callback_data": "quit"}]
]
})

Related

Adaptive card in teams not workig - REST API

I created a bot (nodejs server) for teams - through bot framework.
I'm trying to send adaptive card that I created through: adaptive cards designer
and I get error :
{"code":"BadArgument","message":"ContentType of an attachment is not set"}
The request body :
{
"type": "message",
"from": {
"id": "xxxxxx"
},
"conversation": {
"id": "xxxxxx"
},
"recipient": {
"id": "xxxxx"
},
"replyToId": "xxxxx",
"text": "some text",
"attachments": [
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "some text"
},
{
"type": "Input.Date",
"separator": true
}
]
}
]
}
I would appreciate help
When adding attachments you'll want to set the contentType and content properties of the attachment object.
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#attachment-object
{
"type": "message",
"from": {
"id": "xxxxxx"
},
"conversation": {
"id": "xxxxxx"
},
"recipient": {
"id": "xxxxx"
},
"replyToId": "xxxxx",
"text": "some text",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "some text"
},
{
"type": "Input.Date",
"separator": true
}
]
}
}
]
}
As per the comments above, this is a pro-active message, but using the Bot Framework libraries are a much better approach than trying to call the bot endpoints directly (I wondered if, by "REST", you meant the Bot Framework endpoint or the Graph Api, but in either case the Bot Framework is easier to work with for proactive messages).
Please see specifically this sample for how to do this in Node.

Unable to post message via the Slack API - getting error 'no_text'

Why am I getting an error 'no_text' ?
The Json below is valid and is taken from the slack documentation example.
In bot.postMessage(channel, '', params) if I populate the second parameter (i.e. replacing ' ' with 'some_text) it prints 'some_text' but without the attachment.
bot.postMessage(channel, 'some_text', params) --> works but the attachment doesn't show up.
const element = {
"text": "Would you like to play a game?",
"response_type": "in_channel",
"attachments": [
{
"text": "Choose a game to play",
"fallback": "If you could read this message, you'd be choosing something fun to do right now.",
"color": "#3AA3E3",
"attachment_type": "default",
"callback_id": "game_selection",
"actions": [
{
"name": "games_list",
"text": "Pick a game...",
"type": "select",
"options": [
{
"text": "Hearts",
"value": "hearts"
},
{
"text": "Global Thermonuclear War",
"value": "war"
}
]
}
]
}
]
}
console.log('JSON.stringify(element): '+JSON.stringify(element));
params = {
icon_emoji: ':r2:',
attachments: JSON.stringify(element)
}
bot.postMessage(channel, '', params).always(function (data) {...}
The issue arises from the lack of a text field in the parameters that is passed to bot.PostMessage. Your params should be
params = {
icon_emoji: ':r2:',
text: "Would you like to play a game?",
response_type: "in_channel",
attachments: element
}
and the element now should start from the actual attachment
const element = [
{
"text": "Choose a game to play",
"fallback": "If you could read this message, you'd be choosing something fun to do right now.",
"color": "#3AA3E3",
"attachment_type": "default",
"callback_id": "game_selection",
"actions": [
{
"name": "games_list",
"text": "Pick a game...",
"type": "select",
"options": [
{
"text": "Hearts",
"value": "hearts"
},
{
"text": "Global Thermonuclear War",
"value": "war"
}
]
}
]
}
]
I met the same issue and found the solution.
The problem is that if only attachments field is added into the payload, it will report no_text error. But if text field is added, slack message will only show the text content.
The solution:
When we want to display attachments, we need to add a basic blocks field instead of text field. Something like
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "bar"
}
}
],
"attachments": [
{
"color": "#FF0000",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "foo"
}
}
]
}
]
}
If putting the above payload into the Slack build kit, it will be a misleading. That's also why I stuck with the issue.
I would recommend to use chat.postMessage test to debug the payload. It will work like a charm.

Display comments on adaptive cards in BOT emulator

I am displaying some data in using adaptive card in BOT emulator,I want to add one comment section there.I tried this way:
{
"type": "Action.ShowCard",
"title": "Comment",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Text",
"id": "test",
"isMultiline": true,
"placeholder": "Enter your comment",
}
],
"actions": [
{
"type": "Action.Submit",
"id":"submit",
"title": "OK",
"data":
{
"test":""
}
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
}
]
but not getting any output when click on OK action.How can we do it?

Action.Submit on Adaptive cards is not calling the next step (not working only in Microsoft Teams works in web chat) : Bot Framework V4

Next steps in the waterfall dialog flow are not getting called while using Action.Submit in Adaptive cards of Microsoft bot framework SDK V4 (Only when integrated with Microsoft teams)
This is nodejs code in Microsoft framework SDK v4. The problem exists only when integrated with Microsoft teams.
I have tried this in web chat and chat emulator. Action.Submit is calling the next steps on the waterfall dialog flow.
** Bot Code in NodeJS **
async endConversation(stepContext){
console.log("on endConversation")
await stepContext.context.sendActivity({
attachments: [CardFactory.adaptiveCard(RatingCard)]
});
return await stepContext.prompt(TEXT_PROMPT, { prompt: '' });
}
async feedback(stepContext){
console.log("on feedback == "+stepContext.result)
}
** Adaptive Card json **
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "medium",
"weight": "bolder",
"color": "accent",
"text": "Rate your experience!"
},
{
"type": "TextBlock",
"separator": true,
"text": "Please rate your experience! Your feedback is very appreciated and will help improve your experience in the future. ",
"wrap": true
},
{
"type": "ColumnSet",
"spacing": "Medium",
"columns": [
{
"type": "Column",
"selectAction": {
"type": "Action.Submit",
"data": "bad"
},
"items": [
{
"type": "Image",
"horizontalAlignment": "Center",
"url": "https://upload.wikimedia.org/wikipedia/commons/e/ed/StarRatingGraphic.jpg",
"size": "auto"
},
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"text": "Bad"
}
],
"width": "auto"
},
{
"type": "Column",
"selectAction": {
"type": "Action.Submit",
"data": "ok"
},
"items": [
{
"type": "Image",
"horizontalAlignment": "Center",
"url": "https://upload.wikimedia.org/wikipedia/commons/e/ed/StarRatingGraphic.jpg",
"size": "auto"
},
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"text": "Ok"
}
],
"width": "auto"
},
{
"type": "Column",
"selectAction": {
"type": "Action.Submit",
"data": "good"
},
"items": [
{
"type": "Image",
"horizontalAlignment": "Center",
"url": "https://upload.wikimedia.org/wikipedia/commons/e/ed/StarRatingGraphic.jpg",
"size": "auto"
},
{
"type": "TextBlock",
"horizontalAlignment": "Center",
"text": "Good"
}
],
"width": "auto"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
Expected :
async method feedback is the next step on the flow which should be called when the user clicks on a star image in adaptive cards.
Actual :
The next step is not getting called. But its going to onMessage method in ActivityHandler base class.
The Interface Looks like
It looks like Teams isn't handling string submit actions very well. I don't know if this is a new problem or if it always worked that way. Try making your submit action data an object instead of a string:
"selectAction": {
"type": "Action.Submit",
"data": {
"rating": "bad"
}
}
This will generate a textless message, so you'll need to extract the rating from the activity's value property. See this post for instructions on transferring a string from an activity's value property to its text property. See my latest blog post for more information about using Adaptive Cards with the Bot Framework.
EDIT: I've discovered that you can simulate an imBack in Teams using the format in this document:
{
"type": "Action.Submit",
"title": "Click me for imBack",
"data": {
"msteams": {
"type": "imBack",
"value": "Text to reply in chat"
}
}
}

Dialogflow Fulfillment LINE custom payload

I am creating Dialogflow fulfillment webhook and use https://github.com/dialogflow/dialogflow-fulfillment-nodejs
I want to use quick reply in LINE and use Suggestion, but it is not working as I want it like this quick reply. Then I decide to try Custom Payload, but it is not working.
My code is like this
function testQuickReplyHandler(agent) {
let payload = {
"messages": [
{
"type": "text",
"text": "Select your favorite food category or send me your location!",
"quickReply": {
"items": [
{
"type": "action",
"action": {
"type": "message",
"label": "Sushi",
"text": "Sushi"
}
},
{
"type": "action",
"action": {
"type": "message",
"label": "Tempura",
"text": "Tempura"
}
},
{
"type": "action",
"action": {
"type": "location",
"label": "Send location"
}
}
]
}
}
]};
agent.add(new Payload('LINE', payload));
}
Am I missing something? I also try removing "messages" field, but also not working
agent.add(new Payload('LINE', payload)); => agent.add(new Payload(agent.ACTIONS_ON_GOOGLE, payload));
Or any payload you like

Resources