In MS Team Adaptive Card, how do I specify the server it post to? - json

I am trying to use Action.Submit in my adaptive card to hit my Google Cloud Function. Where do I specify where to send the submission to? The reason I am doing this is I want to skip building a full chat server due to time constraint.
Example of Adaptive Card, no property to specify post URL:
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Present a form and submit it back to the originator"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "What is your first name?"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "What is your last name?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Action.Submit",
"data": {
"x": 13
}
}
]
}

Adaptive cards aren't developed specifically for bot service.
so working with them needs some tricks , in your case if you are trying to send a request that contain adaptive card inputs you need to know :
when the user click the submit button the adaptive card will send a message to bot activity handler on behalf of the user, this message contains a JSON object (you can view this object by adding this line in the bot onMessage function.
console.log(context.activity)
you can get the data from this meesage by using :
context.activity.value.firstName (to get the firstName sent by the adaptive card)
Now you can send your request to the server i prefer using Axios .

Related

Slack JSON - Custom Bot Username and Icon

I'm looking to send out a Post json request using Zapier's webhook function, together with Slack's incoming webhook set up.
I'm using block kit to develop the message style, and so far that's worked great. However, I'd like my bot to display with a custom username and emoji/icon and I'm having trouble.
Here is the JSON payload I'm trying, based off this tutorial https://api.slack.com/methods/chat.postMessage#args
The post seems to ignore the first two lines and posts as the standard bot name
{
"as_user": false,
"username": "test",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*78 Varet St #14*\n 2 Bed / $2300 \n <#ben> \n 3rd Deposit This Month"
},
"accessory": {
"type": "image",
"image_url": "https://p.sharinpix.com/3/3521a32/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2I2M2RkZTY4LWZkMDMtNGZlYy04OGUxLWYwZjA0N2E4NjQ3NS90aHVtYm5haWxzL29yaWdpbmFsLWI5MTdlNzAzY2U2LmpwZw/77-varet-st-building.jpg?timestamp=1639154285",
"alt_text": "cute cat"
}
},
{
"type": "divider"
}
]
}
Any help would be greatly appreciated!
If you just want to modify the icon and name of your bot ( will be the same throughout the app ), you should be able to do that on https://api.slack.com/apps/{YOUR_APP_ID}/general? under the Display Information section.
If you want to be able to change it from message to message, you will have to grant your app additional permissions scopes. See https://api.slack.com/methods/chat.postMessage#authorship

Redirecting to Bot from URL

I am working on a .Net core Bot application where I have created an adaptive card and when user clicks it would be redirected to a new URL. Once, redirected I want to add a functionality that after user posts in the URL, he should be redirected back to the BOT with the posted data. Can anyone guide me how to approach this. Below is the sample JSON we have created for redirecting user to URL.
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "This card's action will open a URL"
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Action.OpenUrl",
"url": "https://adaptivecards.io"
}
]
}
if you are asking about a Teams bot then you should follow the pattern for a Bot Task Module
Bot message + Card
Activate Task module (aka pop-up window)
task module can display another Adaptive Card
or a HTML page
Task Module completes and sends back info to your bot using task/submit

Adaptive Cards - Is it possible to enforce that the user typed something in Input Text Field before Action.Submit is allowed

I'm trying to use adaptive cards on MS Teams to capture some user input text before they click on submit. One of the things I would like to have is that I want the user to input some non-empty string before the Action.Submit is allowed to go through.
Is that an existing support feature?
Thanks!
This feature, called Input Validation, is part of the upcoming v1.3 release, which will be available in Teams in the next few months. Here is a same that uses the "required" property to indicate something must be entered.
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"body": [
{
"type": "Input.Text",
"id": "name",
"placeholder": "First, last",
"label": "Please enter your name",
"isRequired": true,
"errorMessage": "Name is required"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Save"
}
]
}
You can learn about it here. https://developer.microsoft.com/en-us/office/blogs/adaptive-cards-community-call-july-2020/

How to link QnA Maker answer in Adaptive Card=

I'm rather new with these technologies so bear with me. I have successfully deployed Bot Framework and linked QnA Maker to it. I am using Adaptive Card for first response and i want images in that adaptive card to (when clicked) to generate answer from QnA Maker. How can i link these images to generate QnA Maker answer? Is there a way to just give it URL that would trigger QnA Maker?
You could use the data property in your Adaptive Card to send a message payload to the Bot, which would then trigger the QnA answer.
For example, in the data property, if you put something like 'How do I upload a file', so when the image is clicked, the payload will be 'How do I upload a file' and will be sent to the Bot, where the QnA service should respond in kind with the correct answer.
{
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"style": "Person",
"url": "${creator.profileImage}",
"size": "Small",
"selectAction": {
"type": "Action.Submit",
"id": "image",
"title": "image",
"data": "show me the text 'image'"
}
}
],
"width": "auto"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2"
}

How do we post messages to event grid topics?

I have created event grid topic in azure using event schema = "Event Grid Schema".
The next steps for me is trying to send messages to that event grid topic so the subscribers can do something when the message has been successfully received in event grid topic.
However, I had a problem when sending the message to event grid topic. It always reject my JSON request with error "Required property 'subject' was not set. even tough, I have explicitly set the subject in my JSON post body.
I have also add 'aeg-sas-key' value in header for authentication purposes.
Here is an example of my JSON format:
{
"id": "19291",
"subject": "myapp/vehicles/motorcycles",
"topic": "VehicleData",
"eventType": "statusupdated",
"eventTime": "2019-05-12T18:41:00.9584103Z",
"data":{
"firstName": "Jason",
"postalAddress": "xyz"
},
"dataVersion": "1.0",
"metadataVersion": "string"
}
and Here is the output:
{
"error": {
"code": "BadRequest",
"message": "Required property 'subject' was not set. Report '433759ee-6570-466e-ae12-a6dc5fccbfe1:5/14/2019 4:01:32 AM (UTC)' to our forums for assistance or raise a support ticket.",
"details": [
{
"code": "InputJsonInvalid",
"message": "Required property 'subject' was not set. Report '433759ee-6570-466e-ae12-a6dc5fccbfe1:5/14/2019 4:01:32 AM (UTC)' to our forums for assistance or raise a support ticket."
}
]
}
}
Any idea why it always ask for subject even tough I have provided the subject in my JSON?
Based on the docs:
Post to custom topic for Azure Event Grid
Azure Event Grid event schema
use the following payload:
[
{
"id": "19291",
"subject": "myapp/vehicles/motorcycles",
"topic": null,
"eventType": "statusupdated",
"eventTime": "2019-05-12T18:41:00.9584103Z",
"data": {
"firstName": "Jason",
"postalAddress": "xyz"
},
"dataVersion": "1.0",
"metadataVersion": null
}
]
If you created the topic using the Azure Portal, did you somewhere specify the inputSchemaMapping?
According to the specifications here: https://learn.microsoft.com/en-us/rest/api/eventgrid/topics/createorupdate
You need to specify a inputSchemaMapping when opting for the CustomEventSchema.