Hi Im a beginner to DialogFlow (Api.ai) and I want to make a currency converter. I have a json file hosted on 000 webhost and it look like this.
{
"currency": [
{
"currency": "USD",
"buying": "158.70",
"selling": "162.50",
},
{
"currency": "GBP",
"buying": "190.00",
"selling": "195.98",
},
]
}
I want to get exchange rates from this JSON and display on DialogFlow bot when the user tells which currency they want.
Eg: user asks bot to show USD rates and bot should get data from json and display to the user.
How should I do this? please help. Hope my English is clear since English isnt my native language. thanks
That depends on where you had like to write the response. You can either directly add your responses in dialogflow or can write a webhook to parse the request & send a response. Webhook is something where your actual business logic lies.
If you want to send your own json as given in your question, you can consider writing custom payload in dialogflow.
{
"facebook": {
"attachment": {
"type": 4,
"payload": {
"currency": [{
"currency": "USD",
"buying": "158.70",
"selling": "162.50"
}]
}
}
}
}
Writing custom payload has different format depending on your integration channel. https://dialogflow.com/docs/rich-messages#custom_payload. If want to go by webhook, please check https://dialogflow.com/docs/fulfillment. Hope, this answers your query.
Related
I am POSTING a request to an API to retrieve information about multiple companies.
I am using the following JSON string to retrieve company information about multiple companies in POSTMAN.
In the example below I'm trying to retrieve information about yahoo and google, however I just keep on getting informaton for Google.
I'm sure I need to add "Value" somewhere, but not sure where.
{
"criteria": {
"name":"yahoo,google",
"countryCodes": {
"mode": "any",
"values": ["gb"]
},
"creditRisk": {
"values": [
"VERY_LOW"
]
}
}
}
Any thoughts?
Have a little problem.
I have a feature postUser with request body, which I provide inside this feature.
Body doens't have unique data, it filled manually.
I know that I can read this requestBody from requestBody.json but I dont know how to connect data generator to this json and even if this a possible.
So, my json looks like this
{
"first_name": "test",
"last_name": "user",
"email": "test#sjdas.com",
"phone_number": "12341415",
"image": "",
"status": "INACTIVE",
}
And I want to have dataGenerator inside this json like this
{
"first_name": "#(userName)",
"last_name": "#(userLastName)",
"email": "#(userEmail)",
"phone_number": "#(userPhoneNumber)",
"image": "",
"status": "INACTIVE",
}
Is this possible to have the next scenario if yes, how can I do this?
* path 'user'
And request requestBody
When method Post
Then response 200
P.S. I'm a newbie in Java, so I don't know how to resolve this(
Found solution.
We can't use a data generator inside of the JSON. But we can set the randomly generated value into a JSON file before making the POST request.
All of this should be described inside feature and also JavaFaker should be connected.
I'm trying to change the JSON response I'm getting from a request I make using Logic apps like this:
This request will get the following response:
{
"invoiceID":1,
"formType":"invoice",
"amount":449,
"currency":"eur",
"description":"Invoice real estate",
"period":{"end":20122019,"start":20122020},
"owner":{
"id":91434,
"firstname":"John",
"lastname":"Doe",
"dateOfBirth":1121993,
"phoneNumber":345435435,
"countryOfBirth":"Nederland",
"IBAN":"NL28 ABNA 743734g763474324"
},
"property":{
"id":105,
"type":"apartment",
"address":"ghost lane 13",
"ZIP":"7888 CK",
"State\/Province":"Groningen",
"country":"Nederland",
"construction-year":15072009,
"previousOwners":9
},
"previousProperties":[54,193,11,454,18]
}
Now I'm trying to compose the JSON of above to another json structure, for example to this:
{
"general": {
"invoiceID": 12,
"formType": "invoice",
"amount": 449,
"currency": "eur",
"description": "Invoice real estate",
"period": {
"end": 20122019,
"start": 20122020
}
}
}
I tried using the Compose action for this:
Finally I return the response:
]]
This setup does not work and I'm getting the following error:
{"error":{"code":"NoResponse","message":"The server didbnt receive a answer of the upstream-server. The trace-id from the request is 08586376520125765844944852801CU36."}}
When I remove the Compose action from the logic app designer, the flow does work but I'm getting the original JSON response.
UPDATE
I'm getting the following options for my compose configuration:
From your pic, your Response body set the HTTP action body, you need set the Compose output, the below is my test result and i don't get your error. Maybe you could have a look. And looks like in your compose action, you set the value with wrong value, from your requirements, you need set them with HTTP get action output.
I test with a HTTP trigger.
And the below is my compose input:
"general": {
"amount": "#body('HTTP')['amount']",
"currency": "#body('HTTP')['currency']",
"description": "#body('HTTP')['description']",
"formType": "#body('HTTP')['formType']",
"invoiceID": "#body('HTTP')['invoiceID']",
"period": {
"end": "#body('HTTP')['period']['end']",
"start": "#body('HTTP')['period']['start']"
}
}
And here is the response what my postman get.
Hope this could help you.
When using the /page/feed endpoint in the Facebook Graph API I can't figure out how to know if the post was made by a Page or a User
Here's how I call the endpoint right now:
HTTP GET https://graph.facebook.com/v2.8/{page_id}/feed?fields=is_published,from,message
This yields the following JSON response:
{
"data": [
{
"from": {
"name": "Chad Smith", # <-- This is a User
"id": "806273209398023"
},
"message": "A really magical place! Best Christmas...",
"id": "103988597020_1445496708809010"
},
{
"from": {
"name": "Tivoli", # <-- This is a Page
"id": "103988597020"
},
"message": "Hello everybody...",
"id": "103988597020_10154040865527021"
},
]
}
How can I know if the post was from a Page or User without making additional API calls? I've tried using subfields, but can't figure out if they work on the from field.
I solved it by using ?fields=from{name,about} and marking it as a Page if the from JSON contains about.
This is not the best solution, but about is currently the only subfield of from that doesn't fail on User. (e.g. if I was using ?fields=from{fan_count} the Graph API will fail for posts made by User objects.
I am designing a REST call that should deliver information for a location (lat/lon) and consider the user context/configuration.
As the number of user properties is high and nested, I am not sure, what is the correct way to design a new query (GET vs POST). Currently we use a POST request for simplicity - the query payload could look like this, but is custom and very different for each user. It also includes an array of multiple configuration items. Currently the request looks like this:
POST http://api.something.com/locationInformation
{
"location": {
"accuracy": 30,
"coordinates": [
16.34879820048809,
48.230067741347334
],
"provider": "network",
"timestamp": "2016-01-06T12:00:00.000Z"
},
"userConfiguration": [
{
"id": "asdfasdfasdfs09898sdf",
"values": [
"false"
]
},
{
"id": "iojkljio230909sdjklsdf",
"values": [
"99jkjiouio89",
"sdfilkjöjfoi093s09sdf"
]
}
]
}
So my question is: is it in such a case ok to "abuse" a POST request in order to query information?
Is there an elegant way to pass such data using a GET request?
Yes u can pass this data using a GET request by passing it to a request header.
use the header() method.Initialize a String variable say String data=//your json; and pass it to the header as follows header("data",data) in your client while building the request.