Include Video In Alexa Flask-Ask Response - alexa

just want to know how can i play a video as the response for an intent using flask-ask. I'm using this:
#ask.intent('AllYourBaseIntent')
def all_your_base():
return statement('All your base are belong to us') \
.simple_card(title='CATS says...', content='Make your time')
I guess this is not the right way.

Related

Make Alexa speak before executing action with Python SDK

The use case is pretty similar to things that are working already out there. I want Alexa to say something and then execute an action. For example, with the Spotify integration I can ask Alexa to play a playlist:
Alexa play rock playlist
Alexa says "I will play the rock classics playlist in spotify"
Alexa proceeds to play the playlist.
Notice that Alexa spoke BEFORE actually sending the command to the Spotify API asking to play the playlist. So my question is, how can I achieve the same behavior with the python SDK?
class GetNewFactHandler(AbstractRequestHandler):
"""Handler for Skill Launch and GetNewFact Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return (is_request_type("LaunchRequest")(handler_input) or
is_intent_name("GetNewFactIntent")(handler_input))
def handle(self, handler_input):
# type: (HandlerInput) -> Response
logger.info("In GetNewFactHandler")
print("Running action here")
speak = "I will run the action"
return (handler_input.response_builder.speak(speak).response)
I have something similar to the code above. But it always executes the action before Alexa says it will execute it. Is there any way to pass a callback to the response builder? I'm very new to the SDK, sorry if it is too obvious.
You can use Progressive Response
Your skill can send progressive responses to keep the user engaged while your skill prepares a full response to the user's request. A progressive response is interstitial SSML content (including text-to-speech and short audio) that Alexa plays while waiting for your full skill response.
To note, Alexa is not calling the API after saying the speech, it is calling the API while responding to the user to make it looks smooth.
Phython code example
def get_progressive_response(handler_input):
# type: (HandlerInput) -> None
request_id_holder = handler_input.request_envelope.request.request_id
directive_header = Header(request_id=request_id_holder)
speech = SpeakDirective(speech="Ok, give me a minute")
directive_request = SendDirectiveRequest(
header=directive_header, directive=speech)
directive_service_client = handler_input.service_client_factory.get_directive_service()
directive_service_client.enqueue(directive_request)
time.sleep(5)
return
class HelloWorldIntentHandler(AbstractRequestHandler):
# Handler for Hello World Intent
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("HelloWorldIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Hello World!"
get_progressive_response(handler_input)
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response

How to add reactions to messages in discord.py without id

I am new to discord.py coding. I can't find the I'd for arrow up emoji... I've tried client.emojis and others but it doesnt work... pls help or send me all the ids or a website to see all the ids
just type your emoji in :this: form and stic an \ before the emojiname thats it!
when you send it it will come as <:something:1234567890123>
copy the numbers at the end thats your emoji id
same can be done with members and channels just instead of :this: do :#random_dude: and for channels do #general
hope this helps! Goodluck on your development!
I'm not sure what your code looks like, but if you're interacting with your 'message' asyncs you could do this.
emoji = '\N{THUMBS UP SIGN}'
# or '\U0001f44d' or '👍'
await message.add_reaction(emoji)
If you can, can you add your code so I can see where your error might be?
As zjbrown said, the thumbs up emoji can be stored in a string (and sent) using "\N{THUMBS UP SIGN}", "\U0001f44d", or "👍".
You can google a built-in emoji's name to find websites that have emoji descriptions. Sometimes these sites also have the unicode name, but this is not guranteed. If you want to send a custom emoji, you will have to find the emoji's id.
For built-in emojis, you can use RoboDanny's charinfo command (you'll have to add it to your own bot or use the RoboDanny bot in the discord.py support server) to get the unicode name.
If it is a custom emoji, you can send it in chat and get the image url (right click -> copy url). Then, look for the string of numbers before the .png and copy that. (Numbers only - don't copy the beginning of the url!) You can then send custom emojis by using the string <:[emoji name]:[emoji id]> for static emojis and <a:[emoji name]:[emoji id]> for animated emojis.

Errors with multi turn dialog in alexa skills

I have created a skill with name "BuyDog" and its invocation name is "dog app"
So that should mean, I can use the intents defined inside only after the invocation name is heard. (is that correct?)
Then I have defined the Intents with slots as:
"what is {dog} price."
"Tell me the price of {dog}."
where the slot {dog} is of slot type "DogType". I have marked this slot as required to fulfill
Then I have added the endpoint to AWS lambda function where I have used the blueprint code of factskills project in node.js, and done few minor changes just to see the working.
const GET_DOG_PRICE_MESSAGE = "Here's your pricing: ";
const data = [
'You need to pay $2000.',
'You need to pay Rs2000.',
'You need to pay $5000.',
'You need to pay INR 3000.',
];
const handlers = {
//some handlers.......................
'DogIntent': function () {
const factArr = data;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = GET_DOG_PRICE_MESSAGE + randomFact;
}
//some handlers.......................
};
As per the about code I was expecting when
I say: "Alexa open dog app"
It should just be ready to listen to the intent "what is {dog} price." and the other one. Instead it says a random string from the node.js code's data[] array. I was expecting this response after the Intent was spoken as the slot was required for intent to complete.
And when
I say: "open the dog app and Tell me the price of XXXX."
It asks for "which breed" (that is my defined question) But it just works fine and show the pricing
Alexa says: "Here's your pricing: You need to pay $5000."
(or other value from the data array) for any XXXX (i.e. dog or not dog type).
Why is alexa not confirming the word is in slot set or not?
And when
I say: "open the dog bark".
I expected alexa to not understand the question but it gave me a fact about barking. WHY? How did that happen?
Does alexa have a default set of skills? like search google/amazon etc...
I am so confused. Please help me understand what is going on?
Without having your full code to see exactly what is happening and provide code answers, I hope just an explanation for your problems/questions will point you in the right direction.
1. Launching Skill
I say: "Alexa open dog app"
It should just be ready to listen to the intent...
You are expecting Alexa to just listen, but actually, Alexa opens your skill and is expecting you to have a generic welcome response at this point. Alexa will send a Launch Request to your Lambda. This is different from an IntentRequest and so you can determine this by checking request.type. Usually found with:
this.event.request.type === 'LaunchRequest'
I suggest you add some logging to your Lambda, and use CloudWatch to see the incoming request from Alexa:
console.log("ALEXA REQUEST= " + event)
2. Slot Value Recognition
I say: "open the dog app and Tell me the price of XXXX."
Why is alexa not confirming the word is in slot set or not?
Alexa does not limit a slot to the slot values set in the slotType. The values you give the slotType are used as a guide, but other values are also accepted.
It is up to you, in your Lambda Function, to validate those slot values to make sure they are set to a value you accept. There are many ways to do this, so just start by detecting what the slot has been filled with. Usually found with:
this.event.request.intent.slots.{slotName}.value;
If you choose to set up synonyms in the slotType, then Alexa will also provide her recommended slot value resolutions. For example you could inlcude "Rotty" as a synonym for "Rottweiler", and Alexa will fill the slot with "Rotty" but also suggest you to resolve that to "Rottweiler".
var resolutionsArray = this.event.request.intent.slots.{slotName}.resolutions.resolutionsPerAuthority;
Again, use console.log and CloudWatch to view the slot values that Alexa accepts and fills.
3. Purposefully Fail to Launch Skill
I say: "open the dog bark".
I expected alexa to not understand the question but it gave me a fact about barking.
You must be doing this outside of your Skill, where Alexa will take any inputs and try to recognize an enabled skill, or handle with her best guess of default abilities.
Alexa does have default built-in abilities (not skills really) to answer general questions, and just be fun and friendly. You can see what she can do on her own here: Alexa - Things To Try
So my guess is, Alexa figured you were asking something about dog barks, and so provided an answer. You can try to ask her "What is a dog bark" and see if she responds with the exact same as "open the dog bark", just to confirm these suspicions.
To really understand developing an Alexa skill you should spend the time to get very familiar with this documentation:
Alexa Request and Response JSON Formats
You didn't post a lot of your code so it's hard to tell exactly what you meant but usually to handle incomplete events you can have an incomplete even handler like this:
const IncompleteDogsIntentHandler = {
// Occurs when the required slots are not filled
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'DogIntent'
&& handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED'
},
async handle(handlerInput) {
return handlerInput.responseBuilder
.addDelegateDirective(handlerInput.requestEnvelope.request.intent)
.getResponse();
}
you add this handler right above your actual handler usually in the index.js file of your lambda
This might not fix all your issues, but it will help you handle the event when a user doesn't mention a dog.

How to Develop alexa to speak latest response again

In Details:
Example:
user:- asks About Cricket News.
Alexa:- Reads about the new.
If users says come again or replay
user: Come again.
Alexa: Must read it again what it spoke earlier.
How to handle this situation using webhooks.
Thanks in advance.
You can make use of sessionAttributes to keep track of the last response that Alexa spoke. Whenever you return a response just store the speech and re-prompt in sessionAttributes and whenever a ComeAgainIntent is triggered, take the value from the sessionAttributes and respond accordingly.
Ex:
...
"sessionAttributes": {
"lastResponse": {
"speech": "This was my last speech",
"reprompt": "This was my lst reprompt"
}
}
...
Every time before building the response store the response as lastSpeech in session attributes and write a comeAgainIntent or use amazon.REPEAT intent to repeat the response by getting lastSpeech from session attributes.

How to get seller name from Seller Id using Amazon MWS API

I got the PriceChangedNotification by http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_NotificationType.html.
It returns Seller ID of new offer per ASIN.
I need to get the Seller's name by Seller ID.
How can I do that?
What we did is took a list of the sellerID's and did a scrape using a URL like this: https://www.amazon.com/sp?seller=xxxxxxxxxxx for each seller id. Then pull the seller name out of the resulting html (look for id=sellerName) and stored that in a table. Then when I get a PriceChangedNotification, I join to my sellers table to produce my reports, or whatever else I may need.
Keepa has a nice API that can get this for you and lots of other things that MWS won't. It's not free, but it might be worth it if you have a bunch of things you want to get from Amazon and don't want to scrape everything yourself. Unfortunately, it seems MWS keeps becoming more restrictive.
https://keepa.com/#!discuss/t/request-seller-information/790?u=keepa
The rabbit hole brought me here. Considering I spent an hour googling and testing, here it is so the next one may save some time.
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
seller_id = ""
s = requests.Session()
url = f"https://www.amazon.co.uk/sp?seller={seller_id}"
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
"Cookie":'i18n-prefs=GBP;' # won't work without this cookie
}
r = s.get(url, headers=headers)
# >> print(r) --> response 200
soup = BeautifulSoup(r.text, "html.parser")
soup.find("h1", {"id": "sellerName"}).text
important things to note: Amazon blocks scrapers, you'll need to simulate a http request. Use postman to ping the particular URL you are interested in and look at what headers it sends, in particular what cookies it sends. In this case my request wouldn't work without the i18n-prefs cookie.

Resources