I am currently trying to add quick reply button in Facebook Messenger for my Amazon Lex chatbot. This is my code in python but I am getting a syntax error in the line 'responseCard': {
def helpMe(intent_request):
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
return close(
session_attributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': 'It seems like you need help, let me save you from your misery.\n\n'
+ '- If you want to find '
+ 'out what insurance plan is suitable for your dear self, try asking me "Which integrated Shield Plan is right for me?".\n\n '
+ '- If you want me to explain about your current plan, you could try asking me '
+ '"Explain my current plan".\n\n '
+ '- If you wanna listen to my extremely hilarious puns, just type in "joke" and you will not regret it hehe. '
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Help',
'subTitle': 'Select button of choice',
'imageUrl': '',
"buttons":[
{
"text":"recommend plan",
"value":"Which integrated Shield Plan is right for me"
},
{
"text":"current plan",
"value":"Explain my current plan"
},
{
"text":"tell me a joke",
"value":"joke"
}
]
}
]
}
)
I cannot find a solution to my error, can anyone help me?
Facebook Quick Reply Button
Related
I have the following list of dictionaries:
datalist = [
{'Business': 'Business A', 'Category': 'IT', 'Title': 'IT Manager'},
{'Business': 'Business A', 'Category': 'Sourcing', 'Title': 'Sourcing Manager'}
]
I would like to upload to DynamoDB in the following format:
table.put_item(Item={
'Business':'Business A would go here',
'Category':'IT would go here',
'Title':'IT Manager would go here'
},
{
'Business':'Business B would go here',
'Category':'Sourcing would go here',
'Title':'Sourcing Manager would go here'
}
)
I've tried converting the list of dicts to dict first and accessing the elements that way or trying to iterate through the Items parameter but no luck. Any help would be appreciated.
Here's my DynamoDB structure, 3 columns (Business, Category, Title):
{
"Business": {
"S": "Business goes here"
},
"Category": {
"S": "Category goes here"
},
"Title": {
"S": "Title goes here"
}
}
The put_item API call allows you to upload exactly one item, you're trying to upload two at the same time, this doesn't work.
You can batch multiple put items requests using boto3 to decrease the number of API calls. Here's an example adapted from the documentation:
with table.batch_writer() as batch:
for item in datalist:
batch.put_item(
Item=item
)
This will automatically create the batch writes under the hood.
I would like to have an action after given certain output from PyInquirer. The idea is to have a menu to select certain items. When choosing a item, it should launch a script or another action. In this example i've used print("okay") as a example.
from __future__ import print_function, unicode_literals
from PyInquirer import style_from_dict, Token, prompt, Separator
from pprint import pprint
import os
style = style_from_dict({
Token.Separator: '#cc5454',
Token.QuestionMark: '#673ab7 bold',
Token.Selected: '#cc5454', # default
Token.Pointer: '#673ab7 bold',
Token.Instruction: '', # default
Token.Answer: '#f44336 bold',
Token.Question: '',
})
questions = [
{
'type': 'checkbox',
'message': 'Select a VIP build',
'name': 'F5 configuration build',
'choices': [
Separator('= VIPS ='),
{
'name': 'Nieuwe HTTP VIP'
},
{
'name': 'Nieuwe HTTPS VIP'
},
{
'name': 'Niewe VIP'
},
Separator('= Pools ='),
{
'name': 'Nieuwe Pool'
},
{
'name': 'Bestaande pool'
},
Separator('= Pool member ='),
{
'name': 'Nieuwe Pool Members'
},
{
'name': 'Bestaande Pool Members'
},
],
'validate': lambda answer: 'You must choose atleast one option.' \
if len(answer) == 0 else True
}
]
answers = prompt(questions, style=style)
pprint(answers)
if answers == ("{'F5 configuration build': ['Nieuwe HTTP VIP']}"):
print("okay")
So the
if answers == ("{'F5 configuration build': ['Nieuwe HTTP VIP']}"):
print("okay")
Should print okay after choosing the first choice, but it doesn't happend.
Any advice would be welcome!
Edit Spelling
The name should be a value that is easier to evaluate, for example only "F5" the user will not see it.
It is a type of dict data, you must access it through the index.
answers = prompt(questions, style=style)
pprint(answers)
if answers.get('F5', []) == ['Nieuwe HTTP VIP']:
print("okay")
EDIT: This is has been identified as a bug here.
I am trying to make a Google Meet along with a new calendar event. However, for some reason the returning event does not include any conferenceData, not even one with status fail.
Here is my code. I have omitted the authentication step as I do not get an authentication error.
def generateMeet(emails=None, fake=False):
if emails is None:
emails = []
if fake:
return "https://www.google.com", get_random_string(10)
now = datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
inonehour = (datetime.utcnow() + timedelta(hours=1)).isoformat() + 'Z'
event = {
'summary': 'Orb Meeting',
'start': {
'dateTime': now,
'timeZone': 'America/New_York',
},
'end': {
'dateTime': inonehour,
'timeZone': 'America/New_York',
},
'sendUpdates': "none",
'reminders': {
'useDefault': False,
},
'attendees': [{'email': x} for x in emails],
'conferenceDataVersion': 1,
'conferenceData': {
'createRequest': {
'requestID': get_random_string(10),
'conferenceSolutionKey': {
'type': 'hangoutsMeet'
},
}
}
}
ret = service.events().insert(calendarId='primary', body=event).execute()
return ret['conferenceData']['entryPoints'], ret['id']
This returns a key error, as conference data does not exist. Here is the full 'ret' object before I run the return:
{'kind': 'calendar#event', 'etag': '"3197938620273000"', 'id': '5fb6epfe93sceba9scjt1nevsk', 'status': 'confirmed',
'htmlLink': 'https://www.google.com/calendar/event?eid=NWZiNmVwZmU5M3NjZWJhOXNjanQxbmV2c2sgZm9ycmVzdG1pbG5lckBt',
'created': '2020-09-01T14:08:30.000Z', 'updated': '2020-09-01T14:08:30.162Z', 'summary': 'Orb Meeting',
'creator': {'email': '[my email]', 'self': True},
'organizer': {'email': '[my email]', 'self': True},
'start': {'dateTime': '2020-09-01T10:08:28-04:00', 'timeZone': 'America/New_York'},
'end': {'dateTime': '2020-09-01T11:08:28-04:00', 'timeZone': 'America/New_York'},
'iCalUID': '5fb6epfe93sceba9scjt1nevsk#google.com', 'sequence': 0,
'attendees': [{'email': '[my other email]', 'displayName': 'Forrest Milner', 'responseStatus': 'needsAction'}],
'reminders': {'useDefault': False}}
Can anyone tell me why the conferenceData part of my request might be dropped? I am setting the conferenceDataVersion to 1, and using a random string.
I have tried adding dummy "invitees". In this trial, I invited my second gmail account, and in other trials I have invited several dummy accounts with domain "example.com". This updates the attendees, but does not make the conference data appear.
I have also tried waiting a few minutes and then listing all my events. Even after waiting, the conference data was not filled in. When I check my calendar on the GUI (https://calendar.google.com/calendar/r) it also does not have a Google Meet attached.
Thank you for any help.
Yes, it is a bug, if it's high priority you can 'patch' your created event with something like this:
const eventPatch = {
conferenceData: {
createRequest: { requestId: "yourRandomString" },
},
};
let response = await calendar.events.patch({
calendarId: 'primary',
eventId: "createdEventID",
resource: eventPatch,
sendNotifications: true,
conferenceDataVersion: 1,
});
Reference: https://developers.google.com/calendar/create-events#conferencing
The conferenceDataVersion It's not a part of requestBody anymore. Must be passed inside your insert method.
On NodeJS it's something like this:
calendar.events.insert({
calendarId: 'calendarIdHere',
requestBody: yourOldRequestBodyObject,
conferenceDataVersion: 1
});
#André Eccel is correct. Here's a working Python example of how to add a google meet link to your event:
import uuid
request_id = str(uuid.uuid1())
event = {'summary': "My Birthday Party",
'description': "There will be flamingos.",
'start': start,
'end': end,
'recurrence':recurrence,
'attendees': attendees,
'conferenceData': {'createRequest': {
'requestId': request_id,
"conferenceSolutionKey": {"type": "hangoutsMeet"}}}
}
service.events().insert(calendarId=cal_id,body=event,conferenceDataVersion=1).execute()
I'm using Google AdWords Python SDK to create ResponsiveDisplayAds. My code is like below.
adgroup_ad_service = adwords_client.GetService(
service_name = "AdGroupAdService",
version = "v201809"
)
operations = [{
'operator': 'ADD',
'operand': {
'xsi_type': 'AdGroupAd',
'adGroupId': '<AD_GROUP_ID>',
'ad': {
'xsi_type': 'ResponsiveDisplayAd',
'marketingImage': {
'mediaId': '<MEDIA_ID>'
},
'shortHeadline': 'Short Headline',
'longHeadline': 'This is a very long headline',
'description': 'This is a description',
'businessName': 'Test Business Name',
'finalUrls': ['https://www.google.com'],
'squareMarketingImage': {
'mediaId': '<MEDIA_ID>'
}
},
'status': 'PAUSED'
}
}]
ads_response = adgroup_ad_service.mutate(operations)
print("AD RESPONSE : {}".format(ads_response))
But It's giving me, AdGroupAdError.CANNOT_CREATE_DEPRECATED_ADS.
According to the documentation it describe this error as An ad of this type is deprecated and cannot be created. Only deletions are permitted..
But in documentation of the AdGroupAd ResponsiveDisplayAd, is one of the accepted Ad types.
So it would be great if someone can point me a direction to resolve this issue.
Use AddMultiAssetResponsiveDisplayAd instead.
Same result in a different way.
Hope you can make it like i did.
I am trying to make a response card in amazon lex to give out a response card that has a button that leads to another website. Below is the code that I have used in aws lambda python. I have published the chatbot on facebook messenger. But whenever I select the button in fb messenger, the link in the button does not seem to bring me to the website. Is there any way to make the response card button turn into hyperlink button?
def location(intent_request):
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': 'Here is a map'
},
'responseCard': {
'version': '17',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
"buttons":[
{
"text":"Show Google Maps",
"value":"https://www.google.com/maps/search/?api=1&query=nearby+hospitals"
}
]
}
]
}
}
}
As of now you cannot do that using the buttons. The buttons have two parameters text and value. When you click on a button, the value of button is sent to the servers and the text is appended to the chat. So it will just send the value back to Lex but cannot open function as hyperlink.
However you can use image in the response card for the same functionality. imageUrl is the url of the image to be displayed, and attachmentLinkUrl is the url which you want to open. So I would suggest you to remove buttons and use an image of map to be shown and provide your hyperlink in attachmentLinkUrl.
Also, if you want to show multiple hyperlink, you can show multiple cards (upto 10) in a single responseCard.
Below is a sample code:
return {
'dialogAction': {
'type': 'Close',
'fulfillmentState': 'Fulfilled',
'message': {
'contentType': 'PlainText',
'content': message
},
'responseCard': {
'version': '0',
'contentType': 'application/vnd.amazonaws.card.generic',
'genericAttachments': [
{
'title': 'Here is a list of hospitals',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+hospitals',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
},
{
'title': 'Here is a list of medical shops',
'subTitle': 'Below is a map',
'attachmentLinkUrl': 'https://www.google.com/maps/search/?api=1&query=nearby+medical+shops',
'imageUrl': 'https://images.sftcdn.net/images/t_optimized,f_auto/p/95612986-96d5-11e6-af7c-00163ec9f5fa/3771854867/google-maps-screenshot.png'
}
]
}
}
}
You can check this as well for details about response cards.
Hope it helps.