MS Teams Botframework - getting the "from.name" field - bots

I have a bot running from a desktop <> ngrok <> azure <> MS Teams as a webchat. It is written in Python. Is there a way I can read the field from.name via Botframework/Python (the string USERNAME in the example below)?
The documentation says to use recipient.name, but my recipient.name is the bot's name as it is being run as a webchat (not installed in MS Teams).
I see the following POST API info via ngrok.
{ "text": "hello...",
"textFormat": "plain",
"type": "message",
"timestamp": "2022-09-25T05:26:29.629655Z",
"localTimestamp": "2022-09-25T13:26:29.629655+08:00",
"id": "XXXXXX",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/XXXX",
"from": { "id": "XXXXX", "name": "USERNAME", "aadObjectId": "XXXX" },
"conversation": { "conversationType": "personal", "tenantId": "XXXX", "id": "XXXXXX" },
"recipient": { "id": "XXXXXXX", "name": "BOTNAME" },
"entities": [ { "locale": "en-US", "country": "XX", "platform": "iOS", "timezone": "XX/XX", "type": "clientInfo" } ], "channelData": {"tenant": {"id": "XXXXXX"}},"locale": "en-US","localTimezone": "XX/XX"}

If you want to read the field from.name via Botframework/Python.You can use the below code-
name = turn_context.activity.from_property.name
await turn_context.send_activity(
f"It is a good practice to welcome the user and provide personal greeting. For example: Welcome {name}"
)
Reference Sample-https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/03.welcome-user/bots/welcome_user_bot.py#L100

Related

How to trigger Dialogflow ES intent when incoming message is atachment not a text

I have incoming message from Viber bot as attachment (location share) with no text in Dialogflow ES, so I'd like to trigger intent based on that message. Incoming request is like:
"payload": {
"attachments": [
{
"payload": {
"long": ##.####,
"address": "xxxxxxxx",
"lat": ##.#####
},
"type": "location"
}
],
"source": "viber",
"body": {
"sender": {
"language": "en-GB",
"api_version": 10,
"country": "xx",
"id": "xxxxxx",
"name": "xxxx xxxx"
},
"silent": false,
"event": "message",
"message_token": xxxx,
"chat_hostname": "xxxxx",
"message": {
"location": {
"lat": ##.#####,
"lon": ##.#####
},
"type": "location"
},
"timestamp": xxxxx
},
"contact": {
"channelId": xxxx,
"cId": "########",
"contactId": #######
}
}
}
I don't know how to trigger Dialogflow intent, because there are no words I can use as training phrases
I find an easy solution to this:
I only added "location" in events box and Dialogflow accept trigger the intent without any text in the message or training phrases to be marked
But I'm not sure what exactly triggers:
"type": "location"
or
"message": {
"location": {...
Any way it works.

503 Response Error Code - Using Graph API For Indexing Data against Microsoft Search

I have no clue as to why this is happening for this API only. I am getting 503 service unavailable. Can someone please help me in this.
Payload Used:
{
"#odata.type": "microsoft.graph.externalItem",
"acl": [
{
"type": "user",
"value": "****Azure Object ID***",
"accessType": "grant",
"identitySource": "azureActiveDirectory"
},
{
"type": "user",
"value": "*****AZURE OBJECT ID******",
"accessType": "grant",
"identitySource": "azureActiveDirectory"
}
],
"properties": {
"Product": "Product created in manual",
"Company": "ITC Infotech",
"Category": "Mobile",
"Description" : "this is just a dummy description",
"Price": "$20.22",
"HomePage": "https://www.google.com",
"Image": "https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gardenia-royalty-free-image-1580854928.jpg?crop=1xw:1xh;center,top&resize=480:*"
},
"content": {
"value": "this is just a dummy description",
"type": "text"
}
}
Looks like you need to add /external/connections. Please look at this document.

Images hosted in share point aren't displaying when posted to team via webhook

I'm trying to migrate some of our reports from slack to Microsoft Teams.
We are currently posting images and csv files to slack from an Azure Function.
Early on I noticed that I cannot post images directly but I can mention their URLs in the card and a preview displays and clicking on it should take me to the actual image.
I started out thinking it would be pretty straightforward. And i went ahead and started with the webhooks option. The only problem is that the it supports only 2 types of cards and i have virtually no control over the image size and other properties. And if I'm to use the Adaptive Card(any other card), then I would have to ditch webhooks and make use of the Graph API, which I've already started.
Then I started noticing that the images disappear, as in they just not get displayed anymore. I believe that this could be an authentication issue between sharepoint/ teams as mentioned in this answer -
Adaptive cards for MS Teams - images displaying in web interface but not desktop application
Teams in browser shows the images but the desktop app doesn't. Also they aren't displaying in my mobile app for teams too.
I have already modified my existing application to send a copy of the image/file (whatever it creates) to a folder inside the sharepoint which is the back end to this channel in teams (used sharepoint API v1)
And I intend to post a thumbnail card with a url to the images/file in Sharepoint.
It would really help if someone could help me with the below :
Anyway to fix the authentication issue between Sharepoint ~ Teams
Alternate options to send an image, if 1. is not feasible.
Please help :)
Edit :
Adding card JSON :
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Sample Heading",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://upload.wikimedia.org/wikipedia/en/e/ea/FlowersForAlgernon.jpg",
"size": "medium"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Report1",
"text": "Matt Hidinger",
"weight": "bolder",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "none",
"text": "Created {{DATE(2020-02-14T06:08:39Z,SHORT)}}",
"isSubtle": true,
"wrap": true
}
]
}
]
}
]
}
]
}
Adaptive cards are now supported on Incoming webhook. For sending adaptive cards using Incoming Webhooks, You need to follow the Bot Activity Message Type format: format. where you can add the card json to the content field.
Example:
Post Web-hook URL
Request Body:
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Sample Heading",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://upload.wikimedia.org/wikipedia/en/e/ea/FlowersForAlgernon.jpg",
"size": "medium"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Matt Hidinger",
"weight": "bolder",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "none",
"text": "Created {{DATE(2020-02-14T06:08:39Z,SHORT)}}",
"isSubtle": true,
"wrap": true
}
]
}
]
}
]
}
]
}
}
]
}
Result:

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.

Dialogflow - Fulfillment Webhook Response different from Documentation

I'm currently using Dialogflow in combination with fulfillment/webhooks.
In the documentation of the fulfillments there is an example POST request for webhooks:
POST body:
{
"contexts": [
string
],
"lang": string,
"query": string,
"sessionId": string,
"timezone": string
}
The request that I'm receiving on my end is different from what is defined in the documentation. Has somebody an idea why?
This is what I receive:
{
"id": "GUID",
"timestamp": "2018-01-12T12:25:32.202Z",
"lang": "de",
"result": {
"source": "agent",
"resolvedQuery": "Test",
"speech": "",
"action": "",
"actionIncomplete": false,
"parameters": {
"Nummer": ""
},
"contexts": [],
"metadata": {
"intentId": "XYZ",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"intentName": "Intent"
},
"fulfillment": {
"speech": "",
"messages": [{
"type": 0,
"speech": ""
}]
},
"score": 0.6700000166893005
},
"status": {
"code": 200,
"errorType": "success",
"webhookTimedOut": false
},
"sessionId": "GUID"
}
I've found that different invocation sources send slightly different data to the web hook.
For example the Google Action simulator will send different information in the context reply than say the test pane in an intent.
Im guessing that the answer may lie in where/how your calling the web hook.

Resources