How do you call a 3rd party API from inside watson assistant? - python-3.x

Creating a chatbot using IBM's Watson Assistant, and I need to make a determination I'm trying to send the zip code to a third party API that will return the city and state so I know where the client is located so I can (a) know which services are available and (b) have a better idea on how to direct the conversation from there. But I am at a loss as to how to do this.
I can do this from within Python, but trying to code it in a JSON editor doesn't work.

Webhooks are used to do this from inside the Dialog skill in an Assistant.
IBM Watson Assistant webhooks documentation
The docs do not mention it, but the Assistant will POST to the URL with a JSON body containing the parameters you specify as key value pairs. For example if in the Dialog Node the context variable $zipcode equals '99501' and you specify the parameters "key" = zipcode and "value" = "$zipcode".
Then the HTTP post body is
{ "zipcode" : "99501" }
The response from the service is put into another context variable, and this can then be used for other things. For example in the Dialog Node which calls the webhook, in the "Return variable" section put webhook_result_zipcode to put the response into that context variable.
You can also in the dialog node Assistant responds section, return a message which contains some part of the webhook response. For example in the Dialog Node editor
"If assistant recognizes" $webhook_result_zipcode "Respond with" The code is "$webhook_result_zipcode.response.result.sent" This will tell the user the code which is returned deep within the webhook response in response.result.sent in the response body.
You can also click the Cog next to the response, and in the dialog, click ... next to "Assistant responds" and open the context editor. This opens a context editor (at the top of the dialog) which allows setting of another context variable from part of the webhook response. For example under "Then set context" for "Variable" set zipcode and for "Value" set "$webhook_result_zipcode.response.result.sent.zipcode". This will extract a zipcode value from deep within the webhook response and place it in the context variable zipcode.
Of course then you must find a zipcode location service which accepts a HTTP post and looks for the code in the body.

Related

Azure logic apps 'o365 connector' action 'send approval email' returning null for property 'useremailaddress'. Why?

Azure logic apps 'o365 connector' action 'send approval email' returning null for property 'useremailaddress'. Why?
The Azure logic apps documentation for the 'office 365 outlook connector' shows that the 'ApprovalEmailResponse' object returns 'SelectedOption' and 'UserEmailAddress'. I get the correct value back for 'SelectedOption' but 'UserEmailAddress' always returns 'null'.
https://learn.microsoft.com/en-us/connectors/office365/#approvalemailresponse
How do I get the --> email address <-- of the user that selects 'Approve' or 'Reject' buttons in the email? If an email is forwarded to another person I would like to know who (email address) clicked approve or reject.
***This is what I get if I use the recommended settings mentioned in the replies below. For production we want to set "Use only HTML message" and "Show confirmation dialog" both set to "yes".
After reproducing from our end, we understood that the messages which are recorded as HTML messages aren't capturing all the responses. For this, Make sure you have the below parameters set Hide HTML message to 'yes'.
RESPONSE REQUEST IN OUTLOOK
AFTER RESPONSE HAS BEEN RECORDED
UPDATED ANSWER
Logic App outlook connector:
result:
So... It looks like (in this particular action) the only way to get the email address of the person that clicks approve or reject is to not use HTML and to instead rely on using the action card, that is provided by the logic app action, in the email. With 'Hide HTML message' set to 'yes'. However... I was not able to find a way to render my custom card from the one provided in the email. As a workaround, I use markdown in the body of the action. Not great but looks the same as the HTML version I was going-for. If anyone can figure out how to edit/customize the card that is provided in the email by this specific logic app action. Please... let me and Microsoft (sarcasm) know.

How to determine which user clicked on a button

I'm sending messages with block elements (buttons) to channel using Slack API. How can I get the username displayed when someone approves or rejects the request? I send the message using chat.postMessage.
You should have interactivity enabled for your app. Since you are using buttons you need to reference how to handle interactive components. Essentially, you need to give your buttons an action_id which is it's unique identifier and will help you determine the source of the action (including the user) when the button is clicked. You will parse the action payload that sent to your app to get the user information you need and use that information in a subsequent call to chat.postMessage.
I was having trouble getting the user with the payload, using body instead worked for me:
In Bolt Python:
#app.action("approve_button")
def approve_request(ack, say, body, payload):
# Acknowledge action request
ack()
user_details = body['user']
username = user_details['name']
.....

Prevent new context after responding with new ones on Dialogflow

I have an intent with webhook and slotfilling enabled for validation and it have 4 parameters marked as required, so my server can validade the parameter value.
The strategy that I'm trying to use is: reset the context for invalid parameter value, so the dialogflow can ask it again.
Here is an example entering an invalid value:
On responding "Brasília" the webhook makes a request to my server. My server knows that is an invalid value and respond with the context presented on the previous image.
This is the result:
Notice that the first 4 context match with the previous image, its everything ok here. But dialogflow adds another context. That context is a request for the next parameter, called "motivo" and if I respond back, the response will be stored on this param. After this, dialogflow prompts back for the "local" param.
The conversation runs like this:
User: I want to register a call
Dialogflow: From where you want to register? Aracaju, CAB, Itabuna or Salvador?
User: Brasília
Dialogflow: Please, describe the reason
User: My network wireless is not working
Dialogflow: From where you want to register? Aracaju, CAB, Itabuna or Salvador?
...
What was supose to be:
User: I want to register a call
Dialogflow: From where you want to register? Aracaju, CAB, Itabuna or Salvador?
User: Brasília
Dialogflow: From where you want to register? Aracaju, CAB, Itabuna or Salvador?
...
What I need to know: Am'I responding with the correct contexts? Is there a way to prevent dialogflow creating this new "registrar_dialog_params_motivo" after responding with a new contexts?
Obs.: I'm using a Nodejs server, responding the webhook as the docs suggests.
Edit 1: I know that I can use an entity for this situation. However there is some cases that I need to make multiple validations on backend to procede, something like an user id, etc.
If the intent “Intent_Name” has some input_context defined already, then you need to set that context again as output_context and reply something like you have entered an invalid location, and please enter again.
If the intent does not have any input_context, then you can simply reply you have entered an invalid location. Please enter again, and your intent should be able to catch that too. However, this can cause problems as well.
What I would recommend is having another intent “Intent_Name_followup” with an input_context as location_validation_failed in the logic. If the location is incorrect, you can set this in the output_context to reply to the user.

Which AMP extensions can fetch a response from an endpoint?

What AMP extensions can be used to get a response from the server in the form of variable that can be used later, such as in a template or as a parameter to an attribute?
amp-access
The authorization endpoint of amp-access can return "a free-form JSON object":
Here’s a small list of possible ideas for properties that can be returned from the Authorization endpoint:
Metering info: maximum allowed number of views and current number of views.
Whether the Reader is logged in or a subscriber.
A more detailed type of the subscription: basic, premium
Geo: country, region, custom publication region
amp-form
amp-form "allows publishers to render the responses using Extended Templates". The response is expected to be a valid JSON Object. Try the "Hiding input fields after success" demo in the amp-form sample to see it in action.
amp-list
amp-list fetches "content dynamically from a CORS JSON endpoint and renders it using a supplied template". The response must be a JSON object that contains an array property "items".
In addition to {{variable}} substitutions in Mustache templates, you can also use AUTHDATA(variable) elsewhere.
amp-live-list (not quite)
amp-live-list is a "wrapper and minimal UI for content that updates live in the client instance as new content is available in the source document". The page will re-fetch itself, giving the server a change to send new content. If new content is found, AMP will populate a <div items> element with the new (HTML) items. You can't use that as a variable.
It's name doesn't really suggest it, but I think you want AMP-list
https://github.com/ampproject/amphtml/blob/master/extensions/amp-list/amp-list.md
Fetches content dynamically from a CORS JSON endpoint and renders it using a supplied template.

Creating new task through WebHook with Asana API

I am working with a form system very similar to WUFOO that allows me to send data to an external website using WebHooks.
I have been able to connect my form to my ASANA system through Zapier but I cannot seem to get the API system to operate correctly. Can someone please advise or assist me on what I am doing incorrectly here?
In the screenshot note the following:
- Web URL functions for any web URL (https or http)
- HTTP method has POST, PUT, or GET options
- Data format allows me to input virtually anything so I can match up form fields with any necessary names for ASANA.
I simply cannot get the system to connect to ASANA. Please help me.
Screen shot of WebHook Options
I don't have access to your exact form builder but assuming it does what it says it is doing you can try the following. I'll use creating a task as an example.
Create a personal access token in Asana. To do this log in to Asana, click the icon in the top right corner and open "My profile settings". Go to the apps tab and create a personal access token. You will only ever see this token once so create a new one if you lose it. Also retrieve your workspace id, you can get it by opening app.asana.com/api/1.0/workspaces while logged in.
Now back to your form. For the website url place the specific endpoint you want to hit at Asana. For example, lets create a new task:
https://app.asana.com/api/1.0/tasks
Under the HTTP Method you want to select POST
Under the HTTP Headers you want to specify something like (replace 0/1234abcd with your access token):
{
"Authorization": "Bearer 0/1234abcd",
"Content-Type": "application/json"
}
You can use Send Raw Data and specify something like the following in the raw data section (replace 1234 with your workspace id):
{
"data": {
"workspace": 1234,
"name": "The name of the task"
}
}
You can of course add other fields- please see the API reference for more information:
https://asana.com/developers/api-reference/tasks
Let me know if that works for you.

Resources