Twilio Autopilot SMS not accepting media image type - twilio

I wrote a task a while back that would run a collect flow and collect an image using the model on the docs for doing so (https://www.twilio.com/docs/autopilot/actions/collect#questions). It ran flawlessly, and I tested it to make sure it ran as expected.
I made a new account using the company email to migrate my work over, and continue implementing the code, and eventually reached the portion where I needed to integrate that media collection. I used the same code, but it didn't work. The collect flow keeps on triggering the validate portion and telling me that it isn't an accepted type. I have tried it using the exact code from before as well as the exact image, but it still isn't working. The only thing I can think of is if the phone number was set up differently somehow. The message logs show the image as sent and looks fine and I can't find any differences other than that.
Is there anything that might be causing this? Here is the code for reference
{
"actions": [
{
"collect": {
"name": "image_collect",
"questions": [
{
"question": "Please upload an image",
"name": "image",
"type": "Twilio.MEDIA",
"validate": {
"on_failure": {
"messages": [
{
"say": "We do not accept this format. Please send another image."
}
]
},
"allowed_types": {
"list": [
"image/jpeg",
"image/gif",
"image/png",
"image/bmp",
"application/pdf"
]
}
}
}
],
"on_complete": {
"redirect": "https://4894-100-33-3-193.ngrok.io/image_processing"
}
}
}
]
}

Generally, media size causes this issue, just make sure the file size is within the limits.
For more info - https://www.twilio.com/docs/sms/accepted-mime-types

Related

Why is the Azure Devops API telling me that I must have these parameters for my Push request when I already do?

I'm trying to make a Git push request to our Azure Devops server via the API. The address is https://MYSITE.visualstudio.com/MYPROJECT/_apis/git/repositories/2b34d4f7-2c1f-42e7-8861-u0ba34f72b40/pushes?api-version=5.1 and the body is as follows:
{
"commits": [
{
"comment": "Just a dummy commit",
"changes": [
{
"changeType": "edit",
"item": {
"path": "/src/MYPROJECT/MYPROJECT.csproj"
},
"newContent": {
"content": "beans",
"contentType": "rawText"
}
}
]
}
],
"refUpdates": [
{
"name": "refs/heads/TestDummyPRs/upgradeProjectToLatest",
"oldObjectId": "058da4f3328cb1048cb43faf3b5158bc3b025615"
}
]
}
I'm getting the following error:
Web Request Failed after 4 attempts. Request: https://MYSITE.visualstudio.com/MYPROJECT/_apis/git/repositories/2b34d4f7-2c1f-42e7-8861-u0ba34f72b40/pushes?api-version=5.1. Status: BadRequest. Response: Invalid status code [BadRequest]. Response: {"$id":"1","innerException":null,"message":"The parameters are incorrect. A posted push must contain exactly one commit and one refUpdate.\r\nParameter name: newPush","typeName":"Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer","typeKey":"InvalidArgumentValueException","errorCode":0,"eventId":0}
"A posted push must contain exactly one commit and one refUpdate" doesn't seem entirely reasonable as that's exactly what I have in my body. Does anybody know what might be going on here?
Note that I am having no issues making other web requests, such as creating branches or retrieving file contents.
I expected my web request to proceed smoothly, and to create a Push containing the specified commit to the specified refUpdate.
I have made a manual push for via the Azure Devops web interface and caught the network traffic, and I grabbed the following JSON request out of it:
{
"commits": [
{
"changes": [
{
"changeType": 2,
"item": {
"path": "/src/MYPROJECT/MYPROJECT.csproj"
},
"newContent": {
"content": "beans",
"contentType": 0
}
}
],
"comment": "Just a dummy commit"
}
],
"refUpdates": [
{
"name": ""refs/heads/TestDummyPRs/upgradeProjectToLatest",
"oldObjectId": "058da4f3328cb1048cb43faf3b5158bc3b025615"
}
]
}
This seems to be meaningfully identical to the Push I'm making from my code, other than the enum fields using numerical values instead of text. I have tried my code with numerical values for enums, but that didn't change anything about the error.
I found the issue. The web request from my application was being sent with UTF-16 encoding, whereas Postman had defaulted to UTF-8 encoding. I changed my application to use UTF-8 and it worked.

Outgoing Webhook what is the format of the response message?

I have created an outgoing webhook in MS Teams. At mentioning the name specified in the outgoing webhook, it will successfully cause an API call in my app - all fine and good.
According to the documentation, my app is required to respond to that request with a response message. But I absolutely can't find any documentation of the format that is accepted in this response.
The only reference, I can find is this one:
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-outgoing-webhook
Unfortunately, it does not go into detail of what such a message can look like. It only gives an example that this would be acceptable:
{
"type": "message",
"text": "This is a reply!"
}
I would however not like to respond with a simple message, but much rather with something more rich formatted like a card or - in some cases a reaction instead of a message.
Is that possible? Is there any documentation, what other responses are acceptable? Are there other types than just "message" that can be returned?
Alright, here's a quick and dirty way to handle things for teams. For some reason this is not documented very clearly, but what teams requires is for the "Card" to be created as an attachment, instead of just getting the response directly.
What I've done is capture the boilerplate required to house the card first:
string TeamsAdaptiveCardBoilerplate =
#"
{
""type"":""message"",
""attachments"":[
{
""contentType"":""application/vnd.microsoft.card.adaptive"",
""contentUrl"":null,
""content"":{
""$schema"":""http://adaptivecards.io/schemas/adaptive-card.json"",
""type"":""AdaptiveCard"",
""version"":""1.2"",
""body"":[
##BODY##
]
}
}
]
}
";
Then, I build the body (usually, this would not be static text, but it serves well as an example)
string AdaptiveCardBody =
#"
{
""type"": ""TextBlock"",
""text"": ""Here is a ninja cat""
},
{
""type"": ""Image"",
""url"": ""http://adaptivecards.io/content/cats/1.png""
}
";
Next I simple swap out the placeholder with the real body:
var jsonPayload1 = TeamsAdaptiveCardBoilerplate.Replace("##BODY##", AdaptiveCardBody);
And finally, return the assembled payload (converted back into an object so the correct response headers get set):
var payload1 = JsonConvert.DeserializeObject(jsonPayload1);
return (ActionResult)new OkObjectResult(payload1);
From there, you should be good to go.
Note:
For convenience, the entirety of the "content" (and not "body") block is what you'd copy/paste into the adaptivecards.io designer. You might refactor the above to reflect that reality if it was important to you.
Could you please try this sample json { "$schema": "adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.2", "body": [ { "type": "Image", "url": "c.s-microsoft.com/en-us/CMSImages/…" }, { "type": "TextBlock", "text": "Sample image for Adaptive Card..", "wrap": true } ] }

Slack API - how to send multiple images so they are shown in a gallery

When I send multiple images via api using blocks like this:
{
"blocks": [
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Please enjoy this photo of a kitten"
},
"image_url": "http://placekitten.com/500/500",
"alt_text": "An incredibly cute kitten."
}
]
}
Slack shows them like a separate blocks and doesn't combine them into a gallery:
slack screenshot - API
When I upload them using Slack app in one message - it combines them into a gallery:
slack screenshot - with gallery
I've tried blocks, attachments, third-party urls, permalinks after file.upload - the result is the same, Slack doesn't combine them into gallery.
So, the question is - how do I make it that Slack shows several images in a gallery?
UPD:
Just got an answer from Slack developers support:
slack dev support answer screenshot
Unfortunately, horizontal/gallery formatting of images is not possible
using the block kit builder. However, I'm going to go ahead and pass
your email on to our product team so that they can take this into
consideration for future updates.
Based on your comment,
[...] permalinks after file.upload [...]
this related answer might help (I also added this clarification there).
When uploading files and collecting their permalinks, you must link them in the text param in the message payload (putting them in a mrkdwn block in the blocks param will not work).
In javascript, this looks like:
const result1 = await web.files.upload({...})
const result2 = await web.files.upload({...})
await web.chat.postMessage({
text: `Here are files in a gallery view <${result1.file.permalink| ><${result2.file.permalink| >`,
...
})

What is the payload of a richLinkData in Apple Business Chat

I am trying to send a richLink with the Apple Business Chat Sandbox. However I am not able to find out what the correct payload is. The sandbox does not provide a predefined payload for a richLink. Therefore I am using the RAW JSON tab in order to send a richLink.
The example from the apple documentation is not working and I think there are certain parts missing. Does anyone know what information is missing?
{
"richLinkData": {
"url": "https://www.apple.com/ipad-pro",
"title": "iPad Pro",
"assets": {
"image": {
"data": "/9j/4AAQSkZJRgABAQA…………<snipped>…………AAQAB/Z",
"mimeType": "image/jpeg"
}
}
}
}
The example Apple provides is only part of the solution. You must include the additional parameters that are required in an iMessage. The other required parameters are:
id
sourceId
destinationId
v
type
The different types can be found here, but for richLinkData we set it to richLink.
Here is an example with all the necessary parameters minus the data parameter.
{
"v": "<populated on send>",
"id": "<populated on send>",
"sourceId": "<populated on send>",
"destinationId": "<populated on send>",
"richLinkData": {
"url": "https://www.apple.com/ipad-pro",
"title": "iPad Pro",
"assets": {
"image": {
"data": "",
"mimeType": "image/jpeg"
}
}
},
"type": "richLink"}
Copying and pasting this exactly won't work on it's own. You'll need to fill in the data parameter. The data field they provide won't work, because it has been truncated. To use an image of your choice, you will need to fill the data field with the base64 encoding of your image. You can go here to encode your image, but any base64 image encoder will work. You'll want to cut out data:image/jpeg;base64, because that portion is written for <img> elements. If you don't care about having an image, you can just delete the entire assets parameter.

Slack message JSON, image not showing

I'm building a simple Slack integration. I've got a web app running on a public URL that is returning json like so when my slash command is called:
{
"text": "<http://lorempixel.com/image_output/animals-q-c-640-480-4.jpg>"
}
If I paste that JSON in to their format testing tool, it shows the image as expected. But, when I actually test the slash command in Slack, where my web app returns the exact same JSON, Slack shows the image url as a link, but doesn't show the image.
Thoughts?
I got it to work with having the image in the text AND attachment:
{
"parse": "full",
"response_type": "in_channel",
"text": "<http://lorempixel.com/image_output/animals-q-c-640-480-4.jpg>",
"attachments": [
{
"image_url": "http://lorempixel.com/image_output/animals-q-c-640-480-4.jpg"
}
],
"unfurl_media": true,
"unfurl_links": true
}
This doesn't appear to jive with the documentation and other examples I've seen, but at least it's working now!

Resources