Python 3.6 and Flask-Ask
I can't seem to get Alexa to stream audio for my current hobby project (http://github.com/michaeljdietz/jukebox).
I can stream the audio manually through a web browser no problem with the https stream URL in my response object. Both Alexa and the AVS Service Simulator respond with speech and text correctly to the request. The directive appears to be formatted right to me, to the best of my knowledge anyway.
Here is the response to Alexa which should trigger the playback:
{
"version": "1.0",
"response": {
"outputSpeech": {
"text": "Playing the album The Bends by Radiohead on your jukebox",
"type": "PlainText"
},
"speechletResponse": {
"outputSpeech": {
"text": "Playing the album The Bends by Radiohead on your jukebox"
},
"directives": [
{
"playBehavior": "REPLACE_ALL",
"type": "AudioPlayer.Play",
"audioItem": {
"stream": {
"token": "334f1e7e-938d-4dea-a732-45884c6f6db9",
"url": "https://michaeljdietz.me/songs/1426",
"offsetInMilliseconds": 0
}
}
}
],
"shouldEndSession": true
}
},
"sessionAttributes": {}
}
UPDATE: It does seem to work about 1 out of 10 times for the same stream URL. Below is the response on from Alexa when it fails.
{
"version":"1.0",
"context": {
"AudioPlayer":{
"offsetInMilliseconds":0,
"token":"*****",
"playerActivity":"FINISHED"
},
"System": {
"application": {
"applicationId": "*****"
},
"user" {
"userId":"*****"
},
"device": {
"deviceId": "*****",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint":"https://api.amazonalexa.com",
"apiAccessToken":"*****"
}
},
"request": {
"type":"AudioPlayer.PlaybackFailed",
"requestId":"*****",
"timestamp":"2018-01-09T00:02:48Z",
"locale":"en-US",
"currentPlaybackState": {
"offsetInMilliseconds":0,
"token":"*****",
"playerActivity":"FINISHED"
},
"error": {
"message":"Setting up renderers for an unknown media type: UNDEFINED",
"type":"MEDIA_ERROR_UNKNOWN"
},
"token":"*****"
}
}
Based on Amazons blog and documentation, it seems you're missing "type": "AudioPlayer.Play"in your directives.
Related
My main goal is to get all today meetings in a sharepoint site (using python)
What i already do:
Filter meetings properly and get the specific fields
?$filter=fields/fRecurrence eq 1 and fields/EndDate ge '2022-11-08 18:00:00'&$expand=fields($select=Title,EventDate,EndDate,fRecurrence,RecurrenceData,EventType, Duration,TimeZone)
Request all meetings with all needed info, inclusive RecurrenceData (XLM)
There is the HTTP request and a response sample (some items and info as been removed):
REQUEST:
https://graph.microsoft.com/v1.0/sites/[SITE]/sites/[SITE]/lists/[ID]/items?$filter=fields/fRecurrence eq 1 and fields/EndDate ge '2022-11-08 18:00:00'&$expand=fields($select=Title,EventDate,EndDate,fRecurrence,RecurrenceData,Eventype, Duration,TimeZone)
RESPONSE:
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('[SITE]')/sites('[SITE]')/lists('[ID]')/items(fields(Title,EventDate,EndDate,fRecurrence,RecurrenceData,EventType,Duration,TimeZone,RecurrenceID,UniqueId))",
"value": [
{
"#odata.etag": "[TAG]",
"createdDateTime": "2019-09-09T17:42:40Z",
"eTag": "[TAG]",
"id": "2065",
"lastModifiedDateTime": "2019-09-10T08:51:34Z",
"webUrl": "https://[BUISNESS COMPANY].sharepoint.com/teams/[THINGS]/[THINGS]/Lists/[ROOM NAME]/2022_.000",
"createdBy": {
"user": {
"email": "[USER]",
"id": "[UID]",
"displayName": "[USER NAME]"
}
},
"lastModifiedBy": {
"user": {
"email": "[USER]",
"id": "[UID]",
"displayName": "[USER NAME]"
}
},
"parentReference": {
"id": "[ID]",
"siteId": "[BUISNESS COMPANY].sharepoint.com,[UID],[UID]"
},
"contentType": {
"id": "[THINGS]",
"name": "Event"
},
"https://graph.microsoft.com/v1.0/$metadata#sites('[SITE]')/sites('[SITE]')/lists('[ID]')/items(fields(Title,EventDate,EndDate,fRecurrence,RecurrenceData,EventType,Duration,TimeZone,RecurrenceID,UniqueId))/$entity",
"fields": {
"#odata.etag": "[TAG]",
"Title": "TITLE",
"EventDate": "2019-12-10T10:00:00Z",
"EndDate": "2169-09-12T10:00:00Z",
"fRecurrence": true,
"EventType": 1,
"Duration": 3600,
"RecurrenceData": "<recurrence><rule><firstDayOfWeek>mo</firstDayOfWeek><repeat><monthlyByDay tu=\"TRUE\" weekdayOfMonth=\"second\" monthFrequency=\"3\" /></repeat><repeatForever>FALSE</repeatForever></rule></recurrence>",
"TimeZone": [THINGS],
"UniqueId": "[UID]"
}
}, {...}, {...}, ... ]
In "EventDate": "2019-12-10T10:00:00Z" and the "EndDate": "2169-09-12T10:00:00Z" we have the start and end date of the "event", however this event is recurent, and have some "rules" -> RecurrenceData.
QUESTIONS:
HOW CAN I PARSE THE RULES (using python) TO KNOW IF WE HAVE THIS MEETING TODAY (2022-11-08 18:00:00) OR NOT;
2)OR, HOW CAN I MEKE A REQUEST TO THE SERVER AND RECEVE ONLY THE TODAYS MEETINGS (DOESN'T METTER IF RECURENT OR NOT)
Maybe usefull links:
In C#
Sherepoint recurrence data schema
I would like to Delete a VM with its attached resources including Network Interfaces, data disks, OS Disk and Public IP when a certain URL is called with a delete method:
http://servername.com/azr/vm_name/subscription_id/resource_group
However, I'm having some issues attaching the Public IP For deletion.
I'm doing this by:
Calling Azure GET VM API to get the VM and resource details and saving the response JSON into a variable "response_json"
{
"name": "TestAZR",
"id": "/subscriptions/xx-xxx-xx/resourceGroups/xxx-xxx-xx/providers/Microsoft.Compute/virtualMachines/TestAZR",
"type": "Microsoft.Compute/virtualMachines",
"location": "eastus",
"properties": {
"vmId": "xxx-xxx-xxx",
"hardwareProfile": {
"vmSize": "Standard_DS1_v2"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2016-datacenter-gensecond",
"version": "latest"
},
"osDisk": {
"osType": "Windows",
"name": "TestAZR_disk1",
"createOption": "FromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "xx",
"id": "/subscriptions/xx-xxx/resourceGroups/xx=xxx=x/providers/Microsoft.Compute/disks/TestAZR_disk1
},
"deleteOption": "Detach",
"diskSizeGB": 127
},
"dataDisks": [
{
"lun": 0,
"name": "TestAZR_DataDisk_0",
"createOption": "Attach",
"caching": "ReadOnly",
"writeAcceleratorEnabled": false,
"managedDisk": {
"storageAccountType": "Premium_LRS",
"id": "/subscriptions/xx-xxx-/resourceGroups/xx-xxx-x/providers/Microsoft.Compute/disks/TestAZR_DataDisk_0"
},
"deleteOption": "Detach",
"diskSizeGB": 1024,
"toBeDetached": false
},
{
"lun": 1,
"name": "TestAZR_DataDisk_1",
"createOption": "Attach",
"caching": "ReadOnly",
"writeAcceleratorEnabled": false,
"managedDisk": {
"storageAccountType": "Premium_LRS",
"id": "/subscriptions/xx-xxx-x/resourceGroups/xx-xxx-xx/providers/Microsoft.Compute/disks/TestAZR_DataDisk_1"
},
"deleteOption": "Detach",
"diskSizeGB": 1024,
"toBeDetached": false
}
]
},
"osProfile": {
"computerName": "TestAZR",
"adminUsername": "AAAA",
"windowsConfiguration": {
"provisionVMAgent": true,
"enableAutomaticUpdates": true,
"patchSettings": {
"patchMode": "AutomaticByOS",
"assessmentMode": "ImageDefault",
"enableHotpatching": false
},
"enableVMAgentPlatformUpdates": false
},
"secrets": [],
"allowExtensionOperations": true,
"requireGuestProvisionSignal": true
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/xx-xxx-x/resourceGroups/xx-xxx-x/providers/Microsoft.Network/networkInterfaces/testazrexecute35_z1",
"properties": {
"deleteOption": "Detach"
}
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true
}
},
"provisioningState": "Succeeded",
"timeCreated": "2022-09-15T19:04:13.2910488+00:00"
},
"zones": [
"1"
]
}
Modifying the response_json setting each "DeleteOption" with "Delete" so they get deleted with the VM
Sending the response_json in a PATCH API with the request.
Deleting VM with the DELETE VM API
This works for deleting VM along with Network Interface, Data Disks and OS Disk but Public IP doesn't seem to be deleted with Network Interface automatically.
So I tried this alternatively:
I use the GET Network interface API that contains the Public IP name inside:
{
"name": "testazr845_z1",
"id": "/subscriptions/xx-xxx-xx/resourceGroups/xx-xxx-xx/providers/Microsoft.Network/networkInterfaces/testazr845_z1",
"etag": "W/\"xx-xxx-xx\"",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "xx-xxx-",
"ipConfigurations": [
{
"name": "ipconfig1",
"id": "/subscriptions/xxx-xxxx-xx/resourceGroups/xxx-xxx-xx/providers/Microsoft.Network/networkInterfaces/testazr845_z1/ipConfigurations/ipconfig1",
"etag": "W/\"xxx-xxx-xx\"",
"type": "Microsoft.Network/networkInterfaces/ipConfigurations",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "",
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"name": "TestAZR-ip",
"id": "/subscriptions/xxx-xxx-x/resourceGroups/xx-xxx-xx/providers/Microsoft.Network/publicIPAddresses/TestAZR-ip",
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "xx-xxxx-xx",
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Dynamic",
"idleTimeoutInMinutes": 4,
"ipTags": [],
"ipConfiguration": {
"id": "/subscriptions/xxx-xxxx-x/resourceGroups/xx-xxx-xx/providers/Microsoft.Network/networkInterfaces/testazr845_z1/ipConfigurations/ipconfig1"
},
"deleteOption": "Detach"
},
"type": "Microsoft.Network/publicIPAddresses",
"sku": {
"name": "Basic",
"tier": "Regional"
}
},
"subnet": {
"id": "/subscriptions/xx-xxxx-xx/resourceGroups/VPCxAzrDev/providers/Microsoft.Network/virtualNetworks/xx-xx/subnets/alphatest_ase_subnet"
},
"primary": true,
"privateIPAddressVersion": "IPv4"
}
}
],
"dnsSettings": {
"dnsServers": [],
"appliedDnsServers": [],
"internalDomainNameSuffix": ""
},
"macAddress": "",
"enableAcceleratedNetworking":,
"vnetEncryptionSupported":,
"enableIPForwarding":,
"primary":,
"virtualMachine": {
"id": "/subscriptions/xx-xxx-xx/resourceGroups/xxx-xxx/providers/Microsoft.Compute/virtualMachines/TestAZR"
},
"hostedWorkloads": [],
"tapConfigurations": [],
"nicType": "Standard",
"allowPort25Out": true
},
"type": "Microsoft.Network/networkInterfaces",
"location": "eastus",
"kind": "Regular"
}
I save that response into a variable json "network_interface_json", and in it I modify it with {"DeleteOption" : "Delete"} for the Public IP
I send this json in the PATCH API that's listed for deleting resources with VM
https://learn.microsoft.com/en-us/azure/virtual-machines/delete?tabs=rest2%2Ccli3%2Cportal4%2Cportal5
However I'm getting the following error message when sending this request:
{
"error": {
"code": "LinkedAuthorizationFailed",
"message": "The client '123124-12312-xx' with object id '1231-xx-xx' has permission to perform action 'Microsoft.Network/networkInterfaces/write' on scope '/subscriptions/xxx-xx-xx/resourceGroups/xx-xx-x/providers/Microsoft.Network/networkInterfaces/AZRTEST; however, it does not have permission to perform action 'Microsoft.Network/virtualNetworks/subnets/join/action' on the linked scope(s) '/subscriptions/xx-xxx-x/resourceGroups/VPCxAzureDevelopment/providers/Microsoft.Network/virtualNetworks/VPCxAzureDevelopment-eastus/subnets/xxx-xxx-subnet' or the linked scope(s) are invalid."
}
}
So it seems to be a permissions issue? Or maybe the json I'm using isn't correct to send for PATCH API? I've tried removing the subnet part but this doesn't seem to work, open to any suggestions.
I am having trouble with sending a JSON response from my python3.8 lambda function (default lambda_handler function). I am pretty sure I understand what I am doing after reading most of the docs and the Lambda Function Input Event and Response Format. from that resource, it says the only required section is the 'dialogAction' section.
Right now, my lex-bot has 1 intent and one slot. I know that this works because when I add a logger to the code, I can see that my lambda function is recieving confirmed JSON format.
My code tries to send a final response from the lambda function, but when I run the lex-bot in the console I get the following error:
Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse, problem: The validated object is null at [Source: {"dialogAction": {"type": "Close", "fulfillmentState": "Fulfilled", "message": {"contentType": "PlainText", "content": "milk"}}}; line: 1, column: 128]
Here is my python code:
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
# print
item = event["sessionState"]["intent"]["slots"]["MilkProduct"]["value"]["resolvedValues"][0]
logger.debug(item)
return{
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": item
}
}
}
I do not think this is necessary for you to see, but here is what the lex-bot is sending me after it confirms the slot for the intent has been confirmed:
{
"sessionId": "120304235774457",
"inputTranscript": "I want to buy milk",
"interpretations": [
{
"intent": {
"slots": {
"MilkProduct": {
"shape": "Scalar",
"value": {
"originalValue": "milk",
"resolvedValues": [
"milk"
],
"interpretedValue": "milk"
}
}
},
"confirmationState": "None",
"name": "BuyCream",
"state": "ReadyForFulfillment"
},
"nluConfidence": 1
},
{
"intent": {
"slots": {},
"confirmationState": "None",
"name": "FallbackIntent",
"state": "ReadyForFulfillment"
}
}
],
"responseContentType": "text/plain; charset=utf-8",
"invocationSource": "FulfillmentCodeHook",
"messageVersion": "1.0",
"sessionState": {
"intent": {
"slots": {
"MilkProduct": {
"shape": "Scalar",
"value": {
"originalValue": "milk",
"resolvedValues": [
"milk"
],
"interpretedValue": "milk"
}
}
},
"confirmationState": "None",
"name": "BuyCream",
"state": "ReadyForFulfillment"
},
"originatingRequestId": "417dff57-5260-45cc-81a7-06df13fbee9a"
},
"inputMode": "Text",
"bot": {
"aliasId": "TSTALIASID",
"aliasName": "TestBotAlias",
"name": "Shopping",
"version": "DRAFT",
"localeId": "en_US",
"id": "JTGNDOEVQG"
}
}
Can someone please tell me what I am doing wrong? I have been at this for hours and I seriously do not know what I am doing wrong.
Thanks
I try to make payment requesets for different users via https://api.paypal.com/v1/payments/payment, but for some requests, 40%, PayPal api returns HTTP 400 response and for the rest they are fine. the body of requests is similar to:
{
"intent": "sale",
"payer": {
"payment_method": "PAYPAL",
"funding_instruments": [
{
"billing": {
"billing_agreement_id": "B-XXXXX"
}
}
]
},
"transactions": [
{
"amount": {
"currency": "EUR",
"details": {
"subtotal": "11.99",
"tax": "0.0",
"shipping": "0.0",
"handling_fee": "0.0",
"shipping_discount": "0.0",
"insurance": "0.0"
},
"total": "11.99"
},
"invoice_number": "pp_XXXX",
"custom": "\"{\"payment_id\": \"6102645598795\", \"user_id\": \"28233184743\", \"cid\": \"DE:282331858548:30\"}\""
}
],
"redirect_urls": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}
}
and the response is similar to
{
"name": "TRANSACTION_REFUSED",
"message": "The request was refused",
"information_link": "https://developer.paypal.com/docs/api/payments/#errors",
"debug_id": "8e0a927a12",
"code": "TRANSACTION_REFUSED"
}
the response is not informativ.
any idea?
After contacting PayPal support and sharing the debug_id, They inform me that the error is related to an invalid funding source. The issue means the funding source, credit card or bank account is deleted.
i wrote a webhook in python3 and deployed in my own machines the text provided in fulfillmentText is displayed properly but rich response with cards is not displayed. how can i display my response using basic cards?
{
"fulfillmentText": "My train is in Hyderabad",
"fulfillmentMessages": [
{
"card": {
"title": "card title",
"subtitle": "card text",
"imageUri": "https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png",
"buttons": [
{
"text": "button text",
"postback": "https://assistant.google.com/"
}
]
}
}
]
}
this is my code trying to display the content in the form of cards this is exactly what dialogflow aslo expects as a response format
https://dialogflow.com/docs/fulfillment
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": ""
}
},
{
"basicCard": {
"title": "Train",
"image": {
"url": "https://8e39b052.ngrok.io/train.jpg",
"accessibilityText": "Train Image"
},
"buttons": [
{
"title": "WhereIsMyTrain",
"openUrlAction": {
"url": "https://whereismytrain.in/"
}
}
],
"imageDisplayOptions": "WHITE"
}
}
]
}
}
}
}
this worked for me i was not sending it as a payload before