I have simple bot ,I want to set a greating text and add three buttons to it
something like this.
Welcom Johhn to man utd'
-first button
-second button
-third button
here is what I have tried
$ curl -X POST -H "Content-Type: application/json" -d '{
"greeting": [
{
"locale":"default",
"text":"Hello {{user_first_name}}! Welcome to Man utd"
message: {
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [{
"title": "Hi , thanks for messaging videommerce",
"buttons": [{
"type": "postback",
"title": "Select video purpose",
"payload": "purpose"
}, {
"type": "postback",
"title": "How to create video",
"payload": "create"
},{
"type": "web_url",
"url": "https://www.videommerce.com/",
"title": "Talk to us directly (moving to Customerly live chat)"
}],
}]
}
}
}
}
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=token"
What do I need to change to get what I want?
The greeting webhook does not have the attachment property, as you can see here: documentation.
So, your greeting will work only with the parameters locale and text:
$ curl -X POST -H "Content-Type: application/json" -d '{
"greeting": [
{
"locale":"default",
"text":"Hello {{user_first_name}}! Welcome to Man utd"
}]}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=token"
If you want to show some buttons to the user, the correct way is to call another webhook, after you send the greeting one, the persistent-menu, as described here.. This code will do the work:
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type" : "call_to_actions",
"thread_state" : "existing_thread",
"call_to_actions":[
{
"type":"postback",
"title":"Help",
"payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_HELP"
},
{
"type":"postback",
"title":"Latest Posts",
"payload":"DEVELOPER_DEFINED_PAYLOAD_FOR_LATEST_POSTS"
},
{
"type":"web_url",
"title":"View Website",
"url":"http://yoursite.com/"
}
]
}' "https://graph.facebook.com/v2.6/me/thread_settings?access_token=PAGE_ACCESS_TOKEN"
Related
I am trying to build a simple Logic App in Azure, that sends an email with a zip attachment using cURL from a Linux VM.
In the Logic App, without the attachment it is working fine.
But it breaks once Attachment is configured.
JSON schema, When a HTTP request is received:
{
"properties": {
"Attachments": {
"type": "array"
},
"cc": {
"type": "string"
},
"from": {
"type": "string"
},
"html": {
"type": "string"
},
"subject": {
"type": "string"
},
"to": {
"type": "string"
}
},
"type": "object"
}
Config for Outlook Send an email v2, Logic App, Azure
Commands to send email from Linux VM:
# create attachment
echo "abcd" > test.txt
zip test.zip test.txt
# curl to send json to azure logic app, with attachment
curl -vvv --request POST \
--header 'Content-Type: application/json' \
--url 'https://prod-21.southeastasia.logic.azure.com:443/workflows/xxx/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxx' \
--data '{"from": "xxx#outlook.com", "cc": "xxx#outlook.com, "Attachments": [{ "Content-Type": "BASE64_ENCODED_CONTENT", "Name": "test.zip" }], "to": "xxx#outlook.com", "subject": "Hello, World!", "html": "Hey, test email." }'
Error message from the Run History, Logic App, Azure
Full error from the log:
{
"status": 400,
"message": "Parameter 'Attachment Content' cannot be null or empty.\r\nclientRequestId: 40d2dc9c-549b-4608-xxxxxxxxxxxxxxx",
"error": {
"message": "Parameter 'Attachment Content' cannot be null or empty."
},
"source": "office365-sea.azconn-sea.p.azurewebsites.net"
}
Would like to know how to handle the attachment on this scenario. Any documentation would be helpful as well.
Thank you.
Would be also interested in this topic!
Did you try to use --form instead of --data? Or do you already have a solution for this?
I also tried to specify the "Attachments" property in logic apps as:
"properties": {
"Attachment": {
"contentEncoding": "base64",
"contentMediaType": "image/png",
"type": "string"
},
}
...
I'm using Python 3.7 and requests 2.21.0 to integrate payment gateway.
I have the following example form sandbox which works as expected (returns JSON):
curl -X POST https://secure.snd.payu.com/api/v2_1/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer d9a4536e-62ba-4f60-8017-6053211d3f47" \
-d '{
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe#example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"settings":{
"invoiceDisabled":"true"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}'
On the other hand, I have the following Python code
import requests
import json
url = "https://secure.snd.payu.com/api/v2_1/orders"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer d9a4536e-62ba-4f60-8017-6053211d3f47"
}
data = {
"notifyUrl": "https://your.eshop.com/notify",
"customerIp": "127.0.0.1",
"merchantPosId": "300746",
"description": "RTV market",
"currencyCode": "PLN",
"totalAmount": "21000",
"buyer": {
"email": "john.doe#example.com",
"phone": "654111654",
"firstName": "John",
"lastName": "Doe",
"language": "pl"
},
"settings":{
"invoiceDisabled":"true"
},
"products": [
{
"name": "Wireless Mouse for Laptop",
"unitPrice": "15000",
"quantity": "1"
},
{
"name": "HDMI cable",
"unitPrice": "6000",
"quantity": "1"
}
]
}
response = requests.post(url, data=json.dumps(data), headers=headers)
However, instead of JSON response, I'm getting HTML. Any ideas why? When using Python 2.7 I've used urllib and it worked but using urllib to make a call in Python 3.7 produces exactly the same effect, that is HTML instead of JSON.
Response should look like
{
"status":{
"statusCode":"SUCCESS",
},
"redirectUri":"{payment_summary_redirection_url}",
"orderId":"WZHF5FFDRJ140731GUEST000P01",
"extOrderId":"{YOUR_EXT_ORDER_ID}",
}
It was enough to add allow_redirects=False.
Packages :
hapi-swagger: 9.0.1
joi: 13.0.2
Context :
I use the swagger-ui with a swagger.json file generated by hapi-swagger.
I use for hapi-swagger the jsonEditor option set to true.
Which means that i don't enter myself the body in a single text area but i use directly the generated inputs of the UI.
Issue :
Only the key "name" is required in the payload, the other ones are optional by default if i refer to the Joi doc.
Actually the Swagger-UI sends :
curl -X POST
--header 'Content-Type: application/json'
--header 'Accept: application/json'
-d '{
"name":"fzef",
"idsUser": [],
"idsUsergroup":[]
}'
Instead i want that the Swagger-UI to send a request like :
curl -X POST
--header 'Content-Type: application/json'
--header 'Accept: application/json'
-d '{
"name":"fzef",
}'
Swagger UI
Joi Schema
Joi.object().keys({
request: Joi.object().keys({
name: Joi.string().required(),
idsUser: Joi.array().items(Joi.string()),
idsUsergroup: Joi.array().items(Joi.string()),
}),
}),
});
Swagger.json
...
"paths": {
"/addCompany": {
"post": {
"operationId": "postAddcompany",
"parameters": [{
"type": "string",
"default": "1",
"pattern": "/^v[0-9]+$/",
"name": "apiVersion",
"in": "path",
"required": true
},
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/Model 208"
}
}
],
"tags": ["api", "CompanyCommandsAPIPart"],
"responses": {
"default": {
"schema": {
"type": "string"
},
"description": "Successful"
},
}
}
}
}
"definitions": {
...
"Model 208": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"idsUser": {
"$ref": "#/definitions/Model 13",
"type": "array",
"x-alternatives": [{
"$ref": "#/x-alt-definitions/idsFunctionality",
"type": "array"
}, {
"type": "string"
}]
},
"idsUsergroup": {
"$ref": "#/definitions/Model 13",
"type": "array",
"x-alternatives": [{
"$ref": "#/x-alt-definitions/idsFunctionality",
"type": "array"
}, {
"type": "string"
}]
},
},
"required": ["name"]
},
...
}
What can i do to get this request body ?
Do i need to precise a joi method in order that the hapi-swagger parser add a parameter like 'optional' to the swagger.json ?
I found the same issue for the query of a GET method but found no solution:
https://github.com/swagger-api/swagger-editor/issues/684
The JSON Editor component provides the "Properties" and "Edit JSON" buttons to customize the JSON payload, as you can in the component demo here: http://jeremydorn.com/json-editor/. However, Swagger UI 2.x (the version used by hapi-swagger at the time of writing) initializes the JSON Editor with disable_properties: true and disable_edit_json: true so that these buttons are hidden, and the UI does not expose any configuration options to change the JSON Editor options. There is an open issue in the hapi-editor repository on GitHub: https://github.com/glennjones/hapi-swagger/issues/332.
A possible workaround is to tweak the Swagger UI code. Assuming your Swagger UI's index.html uses unminified swagger-ui.js, find the following lines in <hapi-swagger>/public/swaggerui/swagger-ui.js:
disable_properties:true,
disable_edit_json:true,
and replace them with:
disable_properties:false,
disable_edit_json:false,
Now the JSON Editor will have the "Object Properties" button. Click this button to select the properties to be displayed in the form editor and included in the request body. Unselected properties will not be sent in the request body.
I have a scenario in Box of commenting a file using Box Api. I have used Box api to add a comment. When displaying all the comments, it shows commented person name same for all comments.
How should I add a comment to differentiate who has commented it using Box API
Sample comment List:
{
"type": "comment",
"id": "1111",
"is_reply_comment": false,
"message": "Sample Comment 1",
"created_by": {
"type": "user",
"id": "111",
"name": "AAA",
"login": "aaa#aaa.com"
},
"created_at": "2016-08-11T00:01:56-07:00",
"item": {
"id": "78110824178",
"type": "file"
},
"modified_at": "2016-08-11T00:01:56-07:00"
}
{
"type": "comment",
"id": "2222",
"is_reply_comment": false,
"message": "Sample Comment 2",
"created_by": {
"type": "user",
"id": "111",
"name": "AAA",
"login": "aaa#aaa.com"
},
"created_at": "2016-08-11T00:01:56-07:00",
"item": {
"id": "78110824178",
"type": "file"
},
"modified_at": "2016-08-11T00:01:56-07:00"
}
Please help to add comments for different users
To comment as a specific user, you can use the As-User header. Here is an example:
curl https://api.box.com/2.0/comments \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "As-User: USER_ID" \
-d '{"item": {"type": "file", "id": "FILE_ID"}, "message": "YOUR_MESSAGE"}' \
-X POST
I asked another question in another thread that gave me start on Swagger POST, but here I am stuck with another problem.
Here is my parameter definitions in my config json file
"/people/postTest": {
"post": {
"summary": "post test.",
"description": "Test.",
"operationId": "postTest",
"consumes": [
"application/json"
],
"tags": [
"test post"
],
"parameters": [
{
"in":"body",
"name":"body",
"description": "body for the POST request",
"required":true,
"schema": {"$ref":"#/definitions/inBody"}
}
] }}
"definitions": {
"inBody": {
"properties": {
"RequestSystem": {
"type": "string"
}}}}
(copied it from a big file so only took a small part but there is no issues with syntax)
and I am using CURL to post my request
curl -H "Content-Type: application/json" -X POST -d '{"RequestSystem":"IVR"}' http://localhost:8016/people/postTest
and this is the validation error I am getting when I try to start my node server
**ValidationError: "body" is required**
I know I am passing "RequestSystem" parameter but I am not sure where I am making mistakes in setting up my params in my config json file's "parameters". Any help would be appreciated.
I think you need to make required=false
[
{
"in":"body",
"name":"body",
"description": "body for the POST request",
"required":false,
"schema": {"$ref":"#/definitions/inBody"}
}
]
}
}
Try this It should work.