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

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>

Related

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

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)

How to send file upload multipart form in restassured

I want to send below as a Multipart Form in API Body for a POST request:
Upload passing two attributes (KEY) with (VALUE)
Send arquivo (KEY) with (file)
How to do this using REST-Assured
multipart print https://ibb.co/0QQCkQv
attempts:
Response response = (Response)
given()
.relaxedHTTPSValidation()
.header("Content-Type", "multipart/form-data")
.formParam("tipo", "capital_relatorio_faturamento")
.multiPart("arquivo", file, "image/jpg")
enter code here
------------------------------
.formParam("arquivo", "image/jpg")
.multiPart("tipo", "capital_balanco_patrimonial")
.multiPart("arquivo",file)
-------------------------------
.header("Content-Type", "multipart/form-data")
.multiPart("tipo", "capital_comprovante_endereco")
.multiPart("arquivo",file)```
Try
.multiPart("tipo", "capital_balanco_patrimonial")
.multiPart("arquivo", file, "image/jpg")
Rest-assured will automatically add content-type for these.

Graphql post body "Must provide query string."

I use Express-graphql middleware.
I send the following request in the body line:
POST /graphql HTTP/1.1
Host: local:8083
Content-Type: application/graphql
Cache-Control: no-cache
Postman-Token: d71a7ea9-5502-d5fe-2e36-0ae49c635a29
{
testing {
pass(id: 1) {
idn
}
}
}
and have error
{
"errors": [
{
"message": "Must provide query string."
}
]
}
in graphql i can send update in URL.
URL string is too short. i must send update model like
mutation {
update(id: 2, x1: "zazaza", x2: "zazaza", x3: "zazaza" ...(more more fields)...) {
idn
}
}
I think its must be in request body. How can I send 'update' query or that I'm doing wrong?
Post request needs to manage headers info.
Using Http client - Content-Type: application/json
Using Postman client - Content-Type: application/graphql
but request body looks like string
{"query":"mutation{update(id:1,x1:\"zazaz\",x2:\"zazaz\"......){id x1 x2}}"}
If you are using graphql and want to test it using postman or any other Rest client do this.
In postman, select POST method and enter your URL and set Content-Type as application/graphql then pass your query in the body.
Example:
http://localhost:8080/graphql
Mehtod: POST
Content-Type: application/graphql
Body:
query{
FindAllGames{
_id
title
company
price
year
url
}
}
Thats it you will get the response.
Using Postman Version 7.2.2 I had a similar issue. This version of Postman supports Graphql out of the box. Changing the Content-type to application/json fixed it for me.
for me worked like as following:
In the body
In the Headers
Don't forget mark GraphQl [x] on Body settings
And how was quoted before changes the verb to POST.
This generally occurs when your 'express-graphql' doest receive any params. You need to added a json/applicaton parser in your application.
npm install body-parser
eg -
const bodyParser = require('body-parser');
app.use(bodyParser.json()); // application/json
go to the relevant web page and open "inspect" (by write click ->
inspect || Ctrl+Shift+I in chrome)
go to the network tab and copy the cURL command
open the postman ,then import -> raw text
paste the copied command
then,continue ->
Switch content type to JSON.
Like this
Check if you are using correct protocol in your Postman requests.
I used HTTP instead of HTTPS and this caused the same error.
Changes of content-type, raw or json instead of graphql type didn't help.

Is it possible to post files to Slack using the incoming Webhook?

I am trying out the Slack's API using the incoming webhook feature, posting messages works flawlessly, but it doesn't seem to allow any file attachments.
Looking through I understand I have to use a completely different OAuth based API, but creating more tokens just for the purpose of uploading a file seems odd when posting messages works well, is there no way to upload files to slack with the incoming webook?
No, its is not possible to upload files through an incoming Webhook. But you can attach image URLs to your attachments with the image_url tag.
To upload files you need to use the Slack Web API and the files.upload method. Yes, it requires a different authentication, but its not that complicated if you just use a test token for all API calls.
You can see in the Slack API document that it's easy to add an attachment to the POST message to your webhook. Here is a simple example of sending a text message with an attachment in NodeJS:
import fetch from "node-fetch";
const webhook_url = "https://hooks.slack.com/services/xxxx/xxxx/xxxxxxxx"
const url = "https://1.bp.blogspot.com/-ld1w-xCN0nA/UDB2HIY55WI/AAAAAAAAPdA/ho23L6J3TBA/s1600/Cute+Kitten+13.jpg"
await fetch(webhook_url, {
method: "POST",
body: JSON.stringify({
type: "mrkdwn",
text: "Example text",
attachments: [
{
title_link: url,
text: "Your document: <file name>"
},
],
}),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});

Sending binary data using multipart/form-data from a worker with IE11

I'm trying to send a multipart/form-data from a worker with IE. I've already done it with Chrome, Firefox, Safari using formData objects (not supported IE, I need a manual one)
The binary data I'm sending is a crypto-js encrypted data. With formData objects I do:
var enc = new Buffer(encrypted.ciphertext.toString(CryptoJS.enc.Base64), 'base64');
formData.append("userFile" , new Blob([finalEncrypted], {type: 'application/octet-binary'}), 'encrypted')
this works fine generating a multipart like this(missed some parts of it):
request headers:
Accept:*/*
Accept-Encoding:gzip, deflate
Cache-Control:no-cache
Connection:keep-alive
Content-Length:30194
Content-Type:multipart/form-data; boundary=WebKitFormBoundary0.gjepwugw5cy58kt9
body:
--WebKitFormBoundary0.gjepwugw5cy58kt9
Content-Disposition: form-data; name="userFile"; filename="encrypted"
Content-Type: binary
all binary data
--WebKitFormBoundary0.cpe3c80eodgc766r--
With the manual multipart/form-data:
IE11 doesn't accept readAsBinaryString(deprecated)
I would like to avoid sending base64 encoded data(readAsDataURL)(33% payload)
The binary data I'm sending is a crypto-js encrypted data.
I'm trying:
finalEncrypted = new Buffer(encrypted.ciphertext.toString(CryptoJS.enc.Base64), 'base64');
then in my manual multipart I tried to convert the buffer to a binary string:
item.toString('binary')
the multipart result looks looks this:
--WebKitFormBoundary642013568702052
Content-Disposition: form-data; name="userfile"; filename="encrypted"
Content-Type: binary
all binary data
ÐçÀôpRö3§]g7,UOÂmR¤¼ÚS"Ê÷UcíMÆÎÚà/,hy¼øsËÂú#WcGvºÆÞ²i¨¬Ç~÷®}éá?'é·J]þ3«áEÁÞ,4üBçðºÇª bUÈú4
T\Ãõ=òEnýR _[1J\O-ïǹ C¨\Ûøü^%éÓÁóJNÓï¹LsXâx>\aÁV×Þ^÷·{|­'
On the .NET server we check the hash calculated on client versus calculated on server. Server reply that hashes doesn't match. This makes me think that I'm not sending the file correctly.
It looks like you did not yet get a solution, at least you did not post it here if you had one.
On my end I use jQuery which handles the low level nitty gritty of the actual post.
It may be that you are doing one small thing wrong and IE fails on it. Since you do not show what you used with FormData. It is rather difficult to see whether you had a mistake in there.
// step 1. setup POST data
var data = new FormData();
data.append("some_variable_name", "value_for_that_variable");
data.append("some_blob_var_name", my_blob);
data.append("some_file_var_name", my_file);
// step 2. options
var ajax_options =
{
method: "POST",
processData: false,
data: data,
contentType: false,
error: function(jqxhr, result_status, error_msg)
{
// react on errors
},
success: function(data, result_status, jqxhr)
{
// react on success
},
complete: function(jqxhr, result_status)
{
// react on completion (after error/success callbacks)
},
dataType: "xml" // server is expected to return XML only
};
// step 3. send
jQuery.ajax(uri, ajax_options);
Step 1.
Create a FormData object and fills the form data, that includes variables and files. You may even add blobs (JavaScript objects, will be transformed to JSON if I'm correct.)
Step 2.
Create an ajax_options object to your liking. Although here I show your the method, processData, data, contentType as they must be in case you want to send a FormData. At least, that works for me... It may be possible to change some of those values.
The dataType should be set to whatever type you expect in return.
Step 3.
Send the request using the ajax() function from the jQuery library. It will build the proper header and results as required for the client's browser.