Fulfillment Webhook in Python for Dialogflow - python

I want to develop a webhook in Python using Flask. All documentation and tutorials I found online are for Node.js.
How can I include suggestion chips and action cards for some intents, using Python in a webhook?

If you take a look at the Responses doc for Actions on Google, you can see the JSON responses that you can use rather than Node.js.
A response with a suggestion chip has this format:
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "These are suggestion chips."
}
},
{
"simpleResponse": {
"textToSpeech": "Which type of response would you like to see next?"
}
}
],
"suggestions": [
{
"title": "Suggestion 1"
},
{
"title": "Suggestion 2"
},
{
"title": "Suggestion 3"
}
],
"linkOutSuggestion": {
"destinationName": "Suggestion Link",
"url": "https://assistant.google.com/"
}
}
}
}
}
Alternatively you can find a pre-existing library from a third-party developer to provide fulfillment, such as flask-dialogflow.

Related

Build a JSON object using for loop with python

I am new to python and trying to write a simple script that pushes notification to my slack channel about open tickets in my queue.
I am trying to submit the below JSON object to a slack webhook but not sure how to achieve the end result that looks like below.
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "There are *2* open tickets :in the queue\n *Ticket Details *"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*12345* - High CPU usage on prod app1 server"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*54321* - DB parameter modification - ProdDB03"
}
},
{
"type": "divider"
}
]
}
I am doing an API call to an URL that gives me the open ticket details in a JSON format. I am able to parse through it and store the Count (number of open tickets), Ticket ID and the Ticket Description in respective variables.
I would like to create a block for each ticket as below.
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*54321* - DB parameter modification - ProdDB03"
}
}
Just ideas on how to achieve this without actual code would be helpful too.
Thanks

pymsteams. I need to mention a person in message sent by pymsteams. How to do it?

I have installed and connected pymsteams to a channel and able to send messages. I read documentation but didn't find anything related to how to send message with mentioning a person as #me -> mentioning a person in a teams.
that's a beginning of my code:
import pymsteams;
myMessage = pymsteams.connectocard("webhookurl")
.... // here is a logic
myMessage.send()
I believe you can use an AC card. Here is a detailed explanation where I learned it.
There is an issue thread on github requesting exactly this kind of functionality
https://github.com/rveachkc/pymsteams/issues/11
and there is a comment that presents a temporary solution, which is to manually modify the payload attribute of the connectorcard object. This worked for me.
teams_message = pymsteams.connectorcard(webhook)
teams_message.payload = {
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Hello <at>Leonardo</at>"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"msteams": {
"entities": [
{
"type": "mention",
"text": "<at>Leonardo</at>",
"mentioned": {
"id": "leonardo.benitez#contorso.com",
"name": "Leonardo Benitez"
}
}
]
}
}
}]
}
teams_message.send()
The code snippet, thanks to the author for providing it.

error "no_text" at Slack API chat.postMessage even though text attribute is there

I tried out Slack's Bolt framework for Python. I was experimenting with the Calls API and wanted to post the call to the channel, along with some text. So I used chat.postMessage. However, I get an error ("no_text").
Below is my code (token starred out for security):
client.chat_postMessage(
token="**************",
channel="general",
blocks=[
{
"type": "call",
"call_id": slackCallId,
}
],
text="Test of Calls Api"
)
However, in the Slack channel I see this and then call:
I'm not sure why this is happening.
How about this?
[
{
"type": "slackCallId",
"call_id": "test"
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Test of Calls Api"
}
}
]

Problems creating new query DoubleClick Bid Manager - Python

dict = {
"kind": "doubleclickbidmanager#query",
"metadata": {
"dataRange": "LAST_30_DAYS",
"format": "CSV",
"title": "test API"
},
"params": {
"filters": [
{
"type": "FILTER_PARTNER",
"value": "Nestle (GCC&Levant)_PM MENA (2410734)"
}
],
"metrics": [
"METRIC_CLICKS",
"METRIC_UNIQUE_REACH_CLICK_REACH",
"METRIC_UNIQUE_REACH_IMPRESSION_REACH"
]
}
}
r = requests.post('https://www.googleapis.com/doubleclickbidmanager/v1.1/query',data = dict)
This is the code i am trying to use for creating Query for offline report on google bid manager.
It give me following error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
I have tried different ways even tried using the request type call and put the authorization keys in the API call but it didn't work. Surely something is missing can anyone confirm?
You can follow these python exemples for login :https://github.com/googleads/googleads-bidmanager-examples/tree/master/python
But anyway, there is always something wrong after the login, i post another question below : HttpEroor 500 Backend Error and HttpError 403 using DoubleClick Bid Manager API in python

Location widget in messenger platform displays a search bar in mobile version but not in Desktop Version

By using bot functionality provided by facebook messenger platform,
I want users to be able to provide location by using search.
It's working as expected in mobile app of the messenger as it's showing search option. But in the desktop version of the messenger, search option is not showing in location widget.
I wanted to ask that is it expected behavior or I'm missing out something.
Also in browser console, it's showing some error:
ErrorUtils caught an error:
"navigator.permissions.query(...).then(...).done is not a function".
Subsequent errors won't be logged;
see https://fburl.com/debugjs.ja # qtaMy7UNoCv.js:47.
Here's what I've tried so far:
def send_location_with_quick_reply(self, recipient_id, message, quick_replies):
url = self.get_message_url()
payload = {
"recipient":{
"id":recipient_id
},
"message":{
"text": message,
"quick_replies":[{
"content_type": "location"
}]
}
}
# _do_post will hit the send_message API of `Messenger`.
return self._do_post(url, payload)
And here's the response I'm getting after the user chooses the location:
{
"object": "page",
"entry": [{
"id": "128922990987384",
"time": 1505890084176,
"messaging": [{
"sender": {
"id": "1456347437763847"
},
"recipient": {
"id": "128922990987384"
},
"timestamp": 1505890084065,
"message": {
"mid": "mid.$cAAAvskrTvY9kz1Bs4Vengsjpb9L_",
"seq": 2366,
"attachments": [{
"title": "User's Location",
"url": "https:\\/\\/l.facebook.com\\/l.php?u=https\\u00253A\\u00252F\\u00252Fwww.bing.com\\u00252Fmaps\\u00252Fdefault.aspx\\u00253Fv\\u00253D2\\u002526pc\\u00253DFACEBK\\u002526mid\\u00253D8100\\u002526where1\\u00253D12.9703749\\u0025252C\\u00252B77.6361206\\u002526FORM\\u00253DFBKPL1\\u002526mkt\\u00253Den-US&h=ATNsjbke0tPFGIFpCq4MA5l1W6wmiwp0cTfUZNXSSbMDHxygEM4GrVlZmtaebsN4elliFhMSJNmIFwQgn-p_fxnF2hW0VdKTj2z_0hsWnH4dlLZGdQ&s=1&enc=AZN9DwrutbtXSfRAdxQf4bzFSMSO3zujAb0LBOgUt9mz16ZnDn7CSZDBLmnISjfAMbLG6b6H6hn9a3KCb6wOo7dn",
"type": "location",
"payload": {
"coordinates": {
"lat": 12.9703749,
"long": 77.6361206
}
}
}]
}
}]
}]
}
I am using python and drf to integrate with messenger platform.
Yes, this is expected behavior currently.

Categories

Resources