HTTP Post with ContentURL - api

I a using Microsoft Bot Framework and am trying to do a HTTP Post with an image sent to the bot as an attachment. I see a ContentURL in the Attachment object but cannot figure out how to POST the image to my API with RestSharp?
Any Ideas?

There are a couple possibilities here.
First is to send an image as an attachment. Please see this documentation you JSON would look like this:
{
"type": "message",
"from": {
"id": "12345678",
"name": "sender's name"
},
"conversation": {
"id": "abcd1234",
"name": "conversation's name"
},
"recipient": {
"id": "1234abcd",
"name": "recipient's name"
},
"text": "Here's a picture of the duck I was telling you about.",
"attachments": [
{
"contentType": "image/png",
"contentUrl": "http://aka.ms/Fo983c",
"name": "duck-on-a-rock.jpg"
}
],
"replyToId": "5d5cdc723
}
the other possibility is that you could send an image in a card (which has 2 possibilities itself). For this you can see this documentation for rich cards. in this here is an example of the JSON for that
{
"type": "message",
"from": {
"id": "12345678",
"name": "sender's name"
},
"conversation": {
"id": "abcd1234",
"name": "conversation's name"
},
"recipient": {
"id": "1234abcd",
"name": "recipient's name"
},
"attachments": [
{
"contentType": "application/vnd.microsoft.card.hero",
"content": {
"title": "title goes here",
"subtitle": "subtitle goes here",
"text": "descriptive text goes here",
"images": [
{
"url": "http://aka.ms/Fo983c",
"alt": "picture of a duck",
"tap": {
"type": "playAudio",
"value": "url to an audio track of a duck call goes here"
}
}
],
"buttons": [
{
"type": "playAudio",
"title": "Duck Call",
"value": "url to an audio track of a duck call goes here"
},
{
"type": "openUrl",
"title": "Watch Video",
"image": "http://aka.ms/Fo983c",
"value": "url goes here of the duck in flight"
}
]
}
}
],
"replyToId": "5d5cdc723"
}
the second option for cards would be adaptive cards. by using the visualizer you can actually manipulate the JSON and see how it would be rendered in different channels.

Related

How to create a new database on Notion API with the new "Status" property?

Notion API HTTP requests are not working when I add a new "Status" propoerty for a new database creation.
I've been trying for a while to figure out why, sending Notion a simple HTTP POST request with a "Status" breaks it.
If I just replace "Status" with a simple "Select" it works fine...
This is the code that I tried on my latest attempt:
{
"is_inline": true,
"parent": {
"type": "page_id",
"page_id": page_id
},
"icon": {
"type": "emoji",
"emoji": "🐟"
},
"title": [
{
"type": "text",
"text": {
"content": "Catches",
"link": null
}
}
],
"properties": {
"Name": {
"title": {}
},
"Status": {
"status": {
"options": [
{
"name": "Not started",
"color": "default"
},
{
"name": "25% Complete",
"color": "blue"
},
{
"name": "50% Complete",
"color": "blue"
},
{
"name": "75% Complete",
"color": "blue"
},
{
"name": "Done",
"color": "green"
},
{
"name": "Blocked",
"color": "red"
}
]
}
}
}
}
Status ref page on Notions docs: https://developers.notion.com/reference/property-object#status-configuration

Send Commerce Manager catalog product using WhatsApp Cloud API

After successfully adding my catalog from Commerce manager to Whatsapp manager, now I want to send the user this product via WhatsApp cloud API, I have seen the link which is related to the on-permises API, but found no luck.
https://developers.facebook.com/docs/whatsapp/guides/commerce-guides/share-products-with-customers.
my request body code so far:
https://graph.facebook.com/v13.0/{{Phone-Number-ID}}/messages
{
"interactive": {
"messaging_product": "whatsapp",
"to": "9***********",
"type": "product",
"body": {
"text": "text-body-content"
},
"footer": {
"text": "text-footer-content"
},
"action": {
"catalog_id": "11111111111111",
"product_retailer_id": "2222"
}
}
}
error:
{
"error": {
"message": "(#100) The parameter messaging_product is required.",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AZ-AFvM-Nsnm62de34st5mMJxzJ"
}
}
another request
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to" : "**********",
"type": "interactive",
"interactive": {
"type": "product",
"body": {
"text": "body text"
},
"footer": {
"text": "footer text"
},
"action": {
"catalog_id": "1968701893374783",
"product_retailer_id": "5493"
}
}
}
Result: {
"error": {
"message": "(#131009) Parameter value is not valid",
"type": "OAuthException",
"code": 131009,
"error_data": {
"messaging_product": "whatsapp",
"details": "Interactive Message type, 'product' not supported. Supported types ['button', 'list']"
},
"error_subcode": 2494010,
"fbtrace_id": "AntQdhmCkgZ0Xtaz643Bgq"
}
}
Update:
It is supporting from Aug 25, 2022,
You can now include products and services in messages sent to customers, and customers can add them to shopping carts without having to leave the chat thread. Refer to the Sell Products & Services guide to learn how to send Single and Multi-Product messages to customers.
There is no support for product and product_list types in Cloud API, but you can use it in On-Premises API,
Might be it is still in development, You can track the conversations in Facebook Community,
1094784808057904
415039447294216
data = {
"messaging_product": "whatsapp",
"to": m_id,
"type": "interactive",
"interactive":
{
"type": "product_list",
"header": {
"type": "text",
"text": "header text"
},
"body": {
"text": "body text"
},
"footer": {
"text": "footer text"
},
"action": {
"catalog_id": "catalog id",
"sections": [
{
"title": "section title",
"product_items": [
{"product_retailer_id": "product id"},
]},
{
"title": "section title",
"product_items": [
{"product_retailer_id": "product id"},
]},
]
},
}
}

How can i use $ref in json-schema with vue-json-schema-form?

I am trying to generate a form which can have multiple recursive fields. I have used https://codepen.io/crickford/pen/ZmJqwd this demo (I am not using any custom component). Whenever i am using "$ref" it ignores it. I am using vue-json-schema-form. Here is the link of github https://github.com/crickford/vue-json-schema-form.
Even if i use "$ref":"#" it's not working.
My Json-schema is valid. Even if i replace the following schema in codepen i don't get expected result, where as it is giving me proper output by editing schema property of the source in this link http://www.alpacajs.org/docs/api/recursive-references.html
I don't know where am I mistaking !! At least in codepen attached schema code should work.
Kindly guide me or share working demo fiddle with me. Thanks in advance.
Here is my schema:
{
"type": "object",
"title": "",
"properties": {
"Namespace": {
"type": "string",
"title": "Namespace ",
"attrs": {
"placeholder": "Namespace",
"title": "Please enter Namespace"
}
},
"Name": {
"type": "string",
"title": "Display Name : ",
"attrs": {
"placeholder": "Display Name",
"title": "Please enter Display name"
}
},
"SubSteps": {
"type": "array",
"title": "SubSteps",
"items": {
"type": "object",
"title": "Sub step",
"$ref": "#/definitions/SubSteps"
}
}
},
"definitions": {
"SubSteps": {
"type": "object",
"title": "SubStep item",
"properties": {
"Namespace": {
"type": "string",
"title": "Namespace ",
"attrs": {
"placeholder": "Namespace",
"title": "Please enter Namespace"
}
},
"Name": {
"type": "string",
"title": "Display Name : ",
"attrs": {
"placeholder": "Display Name",
"title": "Please enter Display name"
}
},
"SubSteps": {
"type": "array",
"title": "SubSteps",
"items": {
"type": "object",
"title": "Sub step",
"$ref": "#/definitions/SubSteps"
}
}
}
}
},
"required": [
"Name"
]
}
It doesn't look like the library in question supports the use of $ref. Therefore you would have to submit an issue and / or pull request to add the functionality you want.

What is the fragment that represent an item in a json schema links array

Given the following two JSON Schema definitions
Schema A
{
"$schema": "http://json-schema.org/draft-04/hyper-schema",
"title": "Member Resource",
"description": "A Member at a group",
"id": "schemata/member",
"definitions": {
"first_name": {
"description": "the first name",
"example": "Severus",
"minLength": 1,
"maxLength": 255,
"type": "string"
},
"last_name": {
"description": "the last name",
"example": "Snape",
"minLength": 1,
"maxLength": 255,
"type": "string"
},
"member_response": {
"description": "Successful response to a show or search request",
"type": "object",
"additionalProperties": false,
"properties": {
"member": { "$ref": "/schemata/member" }
},
"required": ["member"]
},
"error_response": {
"description": "Error response to a show or search request",
"type": "object",
"additionalProperties": false,
"properties": {
"reference_id": {"$ref": "#/definitions/reference_id"},
"errors": {"$ref": "#/definitions/errors"}
},
"required": [errors"]
}
},
"links": [
{
"description": "Retrieve a member",
"href": "/members/{(%23%2Fschemata%member%2Fdefinitions%2Fidentity)}",
"method": "GET",
"rel": "instance",
"title": "Show",
"targetSchema": {
"description": "Result of a get request. Can be either a success or a failure.",
"type": ["object"],
"oneOf": [
{ "$ref": "#/definitions/member_response" },
{ "$ref": "#/definitions/error_response" }
]
}
},
{
"description": "Search for a member",
"href": "/members/search",
"method": "GET",
"rel": "instance",
"schema": {
"description": "The expected payload for a search request",
"type": "object",
"additionalProperties": false,
"properties": {
"first_name": {
"$ref": "#/definitions/first_name"
},
"last_name": {
"$ref": "#/definitions/last_name"
}
},
"required": ["first_name", "last_name"]
},
"targetSchema": {
"description": "Result of a get request. Can be either a success or a failure.",
"type": ["object"],
"oneOf": [
{ "$ref": "#/definitions/member_response" },
{ "$ref": "#/definitions/error_response" }
]
}
"title": "Search"
}
],
}
Schema B
{
"$schema": "http://json-schema.org/draft-04/hyper-schema",
"title": "Member Resource",
"description": "A Member at a group",
"id": "schemata/member",
"definitions": {
"first_name": {
"description": "the first name",
"example": "Severus",
"minLength": 1,
"maxLength": 255,
"type": "string"
},
"last_name": {
"description": "the last name",
"example": "Snape",
"minLength": 1,
"maxLength": 255,
"type": "string"
},
"search_payload": {
"description": "The expected payload for a search request",
"type": "object",
"additionalProperties": false,
"properties": {
"first_name": {
"$ref": "#/definitions/first_name"
},
"last_name": {
"$ref": "#/definitions/last_name"
}
},
"required": ["first_name", "last_name"]
},
"member_response": {
"description": "Successful response to a show or search request",
"type": "object",
"additionalProperties": false,
"properties": {
"member": { "$ref": "/schemata/member" }
},
"required": ["member"]
},
"error_response": {
"description": "Error response to a show or search request",
"type": "object",
"additionalProperties": false,
"properties": {
"reference_id": {"$ref": "#/definitions/reference_id"},
"errors": {"$ref": "#/definitions/errors"}
},
"required": [errors"]
},
"get_response": {
"description": "Result of a get request. Can be either a success or a failure.",
"type": ["object"],
"oneOf": [
{ "$ref": "#/definitions/member_response" },
{ "$ref": "#/definitions/error_response" }
]
}
},
"links": [
{
"description": "Retrieve a member",
"href": "/members/{(%23%2Fschemata%member%2Fdefinitions%2Fidentity)}",
"method": "GET",
"rel": "instance",
"title": "Show",
"targetSchema": {
"$ref": "#/definitions/get_response"
}
},
{
"description": "Search for a member",
"href": "/members/search",
"method": "GET",
"rel": "instance",
"schema": {
"$ref": "#/definitions/search_payload"
},
"targetSchema": {
"$ref": "#/definitions/get_response"
},
"title": "Search"
}
],
}
Both schemas are functionally the same. The difference is that targetSchema is defined inline in schema A but as a ref in schema B.
I use a library to validate the input and output to and API endpoint. For example when testing my APIs I want to validate that the response to each request returns a JSON object that conforms with targetSchema for that API.
JSON::Validator.fully_validate(
schema,
object_to_test,
:fragment => "/path/to/fragment"
)
In order to validate against the targetSchema for the /members/search API defined above I need to be able to reference its targetSchema.
In schema B I can do
JSON::Validator.fully_validate(
schema,
object_to_test,
:fragment => "#/definitions/get_response"
)
Is it possible to do the above for schema A too? i.e. can I reference the actual targetSchema of the search link directly. Perhaps it might look like the following
JSON::Validator.fully_validate(
schema,
object_to_test,
:fragment => "#/links[1]/targetSchema"
)
or
JSON::Validator.fully_validate(
schema,
object_to_test,
:fragment => "#/links/[SOME_WAY_OF_SPECIFYING_THAT_TITLA_EQL_SEARCH"]/targetSchema"
)
Given your schema, you can reference the search link's targetSchema with the following JSON Pointer(1).
#/links/1/targetSchema
Here 1 is the index of the desired item in the links array. This is the only way to reference an item in an array. To precisely answer the question -- there is no way of specifying the item in the array where title equals "search".
Obviously, referencing the targetSchema using an index is fragile. If you add a link to the schema in the wrong place, your code will break. You would be better off if you looped through the links in code and chose the one you need.
You might ask, "Why is it so difficult to reference a link's targetSchema for validation?" The answer is that targetSchema is not intended for validation. targetSchema is intended to be informational only. It's documentation. The only schema that the response should be responsible for conforming to is the one it declares in the response(2). This is one of the core ideas of REST. The client and server are decoupled. The client doesn't make any assumptions about the response it will get. The response itself should have all the information needed to interpret the response and what you can do next.
https://www.rfc-editor.org/rfc/rfc6901
http://json-schema.org/latest/json-schema-core.html#anchor33

Extracting values from a JSON string

I want to retrieve the different tag values in an NSString.
NSString *test =
{
"data": [
{
"id": "100002319144563_125257217561582",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello Umair Here",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
}
],
"privacy": {
"description": "Everyone",
"value": "EVERYONE"
},
"type": "status",
"application": {
"name": "iPhone",
"id": "213257025359930"
},
"created_time": "2011-07-08T11:59:15+0000",
"updated_time": "2011-07-08T11:59:15+0000"
},
{
"id": "100002319144563_125251050895532",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello testing testing",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
}
]
}
]
}
How can I retrieve the name and message tag values into an array or dictionary?
It looks like a JSON string, so just use one of JSON libraries, like TouchJSON or JSONKit and you can easily extract the data from the structures they will provide you.