How to use Microsoft Graph API chatMessage to send a message with clickable hyperlink in it - api

According the offical guidebook I'm able to send Microsoft Teams message using Microsoft graph API, the message contains a link, and the receiver received the message as plain text, the link is not clickble, how to send a message that enable the receiver to click on it if it's text content with links in it?
POST https://graph.microsoft.com/v1.0/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6#thread.tacv2/messages
Content-type: application/json
{
"body": {
"content": "Hello Dan, please go to www.microsoft.com"
}
}

Teams message support a subset of markdown syntax, so you can encode your link appropriately. More info here: https://support.microsoft.com/en-us/office/use-markdown-formatting-in-teams-4d10bd65-55e2-4b2d-a1f3-2bebdcd2c772
In principle, your example would look like this:
POST https://graph.microsoft.com/v1.0/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6#thread.tacv2/messages
Content-type: application/json
{
"body": {
"content": "Hello Dan, please go to [www.microsoft.com] (https://www.microsoft.com)"
}
}
(I've put a space between ']' and '(' just so it renders here in Stack Overflow properly - remove it before testing. I needed to do that because Stack Overflow itself support is trying to render my markdown)

Related

How to send a message via url with inline buttons

I can send message, sample:
https://api.telegram.org/bot[TOKEN]/sendMessage?chat_id=#[USERNAME]&text=hello
but I want to send message with inline buttons, please help.
This would be the url you are looking for:
https://api.telegram.org/bot[TOKEN]/sendMessage?chat_id=[CHAT_ID]&text=[TEXT]&reply_markup={"inline_keyboard": [[{"text": "hi", "callback_data": "hi"}]]}
You can pass a JSON toreply_markup field. Here this our JSON:
{
"inline_keyboard": [
[
{
"text": "hi",
"callback_data": "hi"
}
]
]
}
I suggest you use an API library to communicate with Telegram. Using bare urls has its own challenges, like sometimes you should url encode your JSON to avoid errors in URL.
For example this is the url-encoded version of above JSON:
%7B%22inline_keyboard%22%3A%20%5B%5B%7B%22text%22%3A%20%22hi%22%2C%20%22callback_data%22%3A%20%22hi%22%7D%5D%5D%7D

How to keep both button text and payload in whatsapp quick reply message template

Whatsapp quick reply request template has option for payload only. In what option we can configure the button text. After lots of searching on internet I did not find proper solution.
Here is the json of button which need to be send in request but it only has the payload option
{
"type": "button",
"sub_type" : "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
# Business Developer-defined payload
"payload":"aGlzIHRoaXMgaXMgY29vZHNhc2phZHdpcXdlMGZoIGFTIEZISUQgV1FEV0RT"
}
]
},
Reference link: https://developers.facebook.com/docs/whatsapp/api/messages/message-templates/interactive-message-templates#request
You need to configure that in the Facebook Business Manager UI or in the Graph API post request when you create the template. When you're sending the message, you can't dynamically configure the text.

How to format text for messages sent with the REST API?

Currently I am sending plain text messages, how can I format the text messages I send visibly within the conversation? Do I need to specify a different content-type or send rich or html format somehow within the REST API? e.g. I'd like to send line breaks (\r\n) or format responses as a list from the Bot.
If possible please provide a curl working example or something I can transfer to Postman. Thanks!
With the following REST API:
"https://circuitsandbox.net/rest/v2/conversations/ConversationID/messages"
Trying to send a message with a line break
content: Hello \r\n World" --or-- "content: "Hello CRLF World"
https://circuitsandbox.net/rest/v2/conversations/<ConversationID>/messages"
"accept", 'application/json'
"content-type", 'application/x-www-form-urlencoded'
"Authorization", "Bearer <Token>"
"content= Hello\r\nWorld"
Expected:
HelloWorld
Actual:
Hello World
The content should be HTML with a limited set of tags supported : strong, i, ul, ol, li and links.
For example : you can set content to :
This is a test<br> It can be <strong> formatted</strong> <i>a little</I>

How to describe a `multipart/form-data` request in blueprint documentation standard?

i'm trying to document an API and one of these endpoints works as multipart/form-data content-type recipient to catch user uploads, and the whole other endpoints works as application/json content-type recipients.
In my documentation i have documented all json requests as properly json objects, but in the multipart/form-data idk how to describe it.
EX 1 - JSON Endpoint:
{
"data": {
"name": "username",
"email": "email#example.com"
}
}
Now i dont know how to describe this object as multipart/form-data object, using de Blueprint API Docs standard.
Can someone help me?

How to pass a file to an API from Azure Logic App

I have a simple Logic App. The trigger is on New file (ex: Dropbox, OneNote, etc.)
I want to pass the filename and the fileContent to a API APP (web Api).
But I got error, or worse the content is null once in the API!
The API is in C#.
How do you pass a file (ex: pdf, png) to and API from Logic App
UPDATE:
In Logic App here my action code:
"UploadNewFile": {
"inputs": {
"method": "post",
"queries": {
"filedata": {
"fileName":"#triggerOutputs()['headers']['x-ms-file-name']",
"fileContent":"#base64(triggerBody())"
}
},
"uri": "https://smartuseconnapiapp.azurewebsites.net/api/UploadNewFile"
},
"metadata": {
"apiDefinitionUrl": "https://smartuseconnapiapp.azurewebsites.net/swagger/docs/v1",
"swaggerSource": "website"
},
"runAfter": {},
"type": "Http"
}
In my API App, If the function is declared like this filedata is null
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile([FromBody] string filedata)
And if I don't add the [FromBody] like that I got an error.
[Route("api/UploadNewFile")]
[HttpPost]
public HttpStatusCode UploadNewFile(string filedata)
Yes you can send binary content to your own API in a few different methods. Our out-of-the-box actions use this as well.
If you want to send the binary contents as the request body
For example, an outgoing request from the Logic App could have binary content and a content-type header of image/png
In this case the swagger for the body of your request should be binary - or:
{ "name": "body",
"In": "body",
"Schema": {
"Type":"string",
"Format": "binary"
} ... }
That should tell the designer that the request body is binary content. If a previous action or the trigger had binary data (e.g. "When a file is added to FTP") and you used that output in the body, it would show up in your custom API inputs as:
"Body": "#triggerBody()"
Notice there are no { and } on the expression (string interpolations) which would convert the binary content to a string. This would send an outgoing request to the connector with the binary content - so your controller just needs to accept binary content and honor the content-type header as needed.
If you want to send binary content in a JSON request
Sometimes you don't want to send binary as the full request, but as a property of another object. For instance a person object may have a name, address, and profile pic all in the request body. In this case we recommend sending the binary content as base64 encdoded. You can use "format": "base64" in swagger to describe a property as this. In code-view would look something like:
"Body": {
"Name": "#triggerBody()['Name']",
"ProfilePic": "#base64(body('Dropbox'))"
}
Hope that helps. Let me know if you have any questions - here is an article on how logic apps preserves content-types as well.
I found how to to it.
I needed to pass the filename in the querystring and the file in the body of the HTTP Request. Today, it's not possible to do it using the design view so you need to go in code view.
In the Logic App code
"queries": {
"fileName": "#{triggerOutputs()['headers']['x-ms-file-name']}"
},
"body": "#triggerBody()"
In the API App code
public HttpResponseMessage UploadNewFile([FromUri] string fileName)
{
var filebytes = Request.Content.ReadAsByteArrayAsync();
[...]
}
A more detailed explanation can be found in this blog post:
http://www.frankysnotes.com/2017/03/passing-file-from-azure-logic-app-to.html