image upload failure from Gupshup chatbot through whatsapp channel - gupshup

I am using this
var image = {"type":"image","originalUrl":"image url here","previewUrl":"thumbnail url here"};
context.sendResponse(JSON.stringify(image));
format for uploading image to gupshup whatsapp chatbot, but image is not been send,
the error it is showing is
{
"meta": {
"api_status": "stable",
"version": "2.21.4"
},
"errors": [
{
"code": 1014,
"title": "Internal error",
"details": "Image file format (application/octet-stream) is not supported"
}
]
}

There is no support for sending the image file as Content-Type application/octet-stream by WhatsApp hence you got the error.
Supported Content-Types are image/jpeg, image/png. Hence, you will have to provide Image URL which ends with image extension .jpg/.jpeg/.png

Related

Unable to get teams message attachment content using graph API

I am able to get message attachment information as shown below but unable to download the file content which is stored in share point site.
"attachments": [
{
"id": "fc323b65-2cee-48d9-9574-0e26eb74e9bb",
"contentType": "reference",
"contentUrl": "https://otdeveloper.sharepoint.com/sites/Test/Shared Documents/General/1Ex.txt",
"content": null,
"name": "1Ex.txt",
"thumbnailUrl": null
}
]
I am using the following get call for the above request with auth token
GET https://graph.microsoft.com/beta/groups/{{TeamId}}/drive/root:/Test/Shared Documents/General/1Ex.txt:/content
I tried the solution posted in
https://github.com/microsoftgraph/msgraph-sdk-javascript/issues/200
but I am getting 404 response.
Could you please check Get message API.You will receive the the attachments info in the response as shown below

Send file/image as a message from local system in Microsoft Team Channel

How can I send the local file/image in Microsoft Teams Channel using Send Message of Microsoft Graph API?
I have followed a document https://learn.microsoft.com/en-us/graph/api/resources/chatmessageattachment?view=graph-rest-1.0 to attach an image when creating a message to send the team channel. I am trying to send the base64 format of an image. But I am getting an error.
{
"error": {
"code": "InternalServerError",
"message": "Failed to process request.",
"innerError": {
"date": "2020-09-25T11:43:02",
"request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"client-request-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
}
}
It seems there is no appropriate API for you to send local file as message directly.
Creating chatMessage in a channel just supports send the file that has been in SharePoint. So, there are two steps to send the local file: first, upload file to SharePoint, then create chatMessage.
1. Upload file to SharePoint:
File smaller than 4MB:
PUT https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/content
Header:
"Authorization" : "Bearer <access-token>"
Body: binary (select binary option in body in postman)
Upload a file using select file option
file-name: is file name along with extension example: test.txt
File greater than 4MB:
GET: https://graph.microsoft.com/v1.0/drives/{{drive-id}}/items/root:/{{file-name}}:/createUploadSession
Header:
"Authorization" : "Bearer <access-token>"
The Get request will return upload url.
PUT <upload url>
Header:
"Authorization" : "Bearer <access-token>"
Body: binary (select binary option in body in postman)
For more details, see here.
2. Create chatMessage:
POST https://graph.microsoft.com/v1.0/teams/{id}/channels/{id}/messages
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Here's the latest budget. <attachment id=\"153fa47d-18c9-4179-be08-9879815a9f90\"></attachment>"
},
"attachments": [
{
"id": "153fa47d-18c9-4179-be08-9879815a9f90",
"contentType": "reference",
"contentUrl": "https://m365x987948.sharepoint.com/sites/test/Shared%20Documents/General/test%20doc.docx",
"name": "Budget.docx"
}
]
}

Unsupported Media Type - 415 error in POST request in Graph Explorer

I am trying out Graph Explorer. I am able to get my profile from https://graph.microsoft.com/v1.0/me/.
But when I try to create a device using the Graph Explorer, it is returning Unsupported Media Type - 415 response.
My request and response are:
Request
POST https://graph.microsoft.com/v1.0/devices
Request headers
Content-type: application/json
Request body
{
"accountEnabled": false,
"alternativeSecurityIds": [
{
"type": 3,
"key": "base64Y3YxN2E1MWFlYw=="
}
],
"deviceId": "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
"displayName": "Test device",
"operatingSystem": "linux",
"operatingSystemVersion": "1"
}
I have given the consent for all permissions under Modify permissions section.
Response
Unsupported Media Type - 415 - 1168ms
{
"error": {
"code": "Request_BadRequest",
"message": "The specified content type 'application/json;odata=minimalmetadata, application/json' contains either no media type or more than one media type, which is not allowed. You must specify exactly one media type as the content type.",
"innerError": {
"request-id": "11235ffc-1fb3-4324-a832-2c92274e98bf",
"date": "2020-04-06T16:55:17"
}
}
}
Edit
value of deviceId in the request data
"DeviceId" AND "Key" that you are passing in Request body should be Unique identifier. Change you sample Device-Id & Key and try again. It worked for me. and you also increased the length of device id by appending 1 at end.
Documentation for accountEnabled here.

InternalServerError when accessing image/sticker and code snippet urls in chat messages returned from Graph Api

I received "InternalServerError" when accessing an image/sticker/code-snippet link in a chat message return from Microsoft Graph Api.
I received the following chat message from Graph Api (not all properties are not listed):
{
"body": {
"contentType": "html",
"content": "<div><div><img alt=\"Sticker image, OH YEAH!\" src=\"https://graph.microsoft.com/beta/teams/2bf9ebf9-8c85-474a-818a-793bc8898757/channels/19:accc034188164562b194965de5f72d3b#thread.skype/messages/1561440945248/hostedContents/aWQ9eF8wLXNhLWQ4LTUxMTExNzY5OWQ4ZTg3YjgwMWUyMDA0ODVlODRkYThmLHR5cGU9MSx1cmw9aHR0cHM6Ly9hcy1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtc2EtZDgtNTExMTE3Njk5ZDhlODdiODAxZTIwMDQ4NWU4NGRhOGYvdmlld3MvaW1nbw==/$value\" style=\"width:334px; height:250px\"><img alt=\"Sticker image, WORKS ON MY MACHINE\" src=\"https://graph.microsoft.com/beta/teams/2bf9ebf9-8c85-474a-818a-793bc8898757/channels/19:accc034188164562b194965de5f72d3b#thread.skype/messages/1561440945248/hostedContents/aWQ9eF8wLXNhLWQ4LTNlYzQxOTFhYjYxODE5NTI1N2Y1YmVmOGI5YjdiY2JmLHR5cGU9MSx1cmw9aHR0cHM6Ly9hcy1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtc2EtZDgtM2VjNDE5MWFiNjE4MTk1MjU3ZjViZWY4YjliN2JjYmYvdmlld3MvaW1nbw==/$value\" style=\"width:375px; height:250px\"></div>\n\n\n</div>"
},
}
Then I tried to access the image link
GET https://graph.microsoft.com/beta/teams/2bf9ebf9-8c85-474a-818a-793bc8898757/channels/19:accc034188164562b194965de5f72d3b#thread.skype/messages/1561440945248/hostedContents/aWQ9eF8wLXNhLWQ4LTUxMTExNzY5OWQ4ZTg3YjgwMWUyMDA0ODVlODRkYThmLHR5cGU9MSx1cmw9aHR0cHM6Ly9hcy1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtc2EtZDgtNTExMTE3Njk5ZDhlODdiODAxZTIwMDQ4NWU4NGRhOGYvdmlld3MvaW1nbw==/$value
Headers:
Authorization: bearer [access_token]
The response was:
500 Internal Server Error
{
"error": {
"code": "InternalServerError",
"message": "Failed to process request.",
"innerError": {
"request-id": "83da292c-f982-44d3-ae07-ce8b10910b65",
"date": "2019-06-25T08:09:35"
}
}
}
Headers:
request-id: 83da292c-f982-44d3-ae07-ce8b10910b65
client-request-id: 83da292c-f982-44d3-ae07-ce8b10910b65
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"Southeast Asia","Slice":"SliceC","Ring":"2","ScaleUnit":"000","RoleInstance":"AGSFE_IN_7","ADSiteName":"SEA"}}
Date: Tue, 25 Jun 2019 08:09:34 GMT
There are 2 images in the chat message. Accessing the other image incurred the same error.
However, if the chat message had only one image, the link worked. If the chat message had more than one images, or more specifically, more than one links to https://graph.microsoft.com/beta/teams/[group_id]/channels/[channel_id]/messages/[message_id]/hostedContents/[content_id]/$value, should it be an image or a code snippet, accessing the links returned me InternalServerError.
Can someone help?

Fail to download event attachments

I have an event with attachment which is about 50 MB.
Below requests are fine:
GET /users/{id}/events/{id}
GET /users/{id}/events/{id}/attachments/{id}?$select=name,size
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('u_id')/events('e_id')/attachments(name,size)",
"value": [
{
"#odata.type": "#microsoft.graph.fileAttachment",
"id": "a_id",
"name": "xxxx",
"size": 51564506
}
]
}
But when I want to get the content of this attachment:
GET /users/{id}/events/{id}/attachments/{id}
it returns
{
"error": {
"code": "ErrorMessageSizeExceeded",
"message": "The message exceeds the maximum supported size., The message exceeds the maximum supported size.",
"innerError": {
"request-id": "426c3bf3-eda8-40c8-afe6-9b83877a328c",
"date": "2018-10-24T02:31:48"
}
}
}
How could I deal with this?
Is it possible to increase the size limit of this API?
Thank you!
According to your describe, I suggest you should to limit your attachment size.
Also, Microsoft Graph currently has a 4MB limit. If you want to download large attachment, you need to write custom download logic which will like the breakpoint Continuingly and it doesn’t more than 30MB.
P.S. In general, the attachment size of main stream's mailbox are between 20MB and 30MB.
reference:
4MB total size of each REST request

Resources