How to show the current playing item (song) in player or queue screen in alexa app - alexa

I am able to send the songs to amazon echo devices and the song is playing. I am not understanding what i have to send to show the song in the player or queue screen in alexa app as it is coming to other music apps like saavn, spotify etc. Please let me know if there are any link or info regarding this.
]1

Check out Amazon's AudioPlayer Interface Reference. It gives a pretty comprehensive guide on how to make the audio interface work. Essentially, it boils down to adding another directive to the list of directives you're returning in your response JSON. For me, this will automatically come up with the audio player screen.
A basic version of the audio directive looks like the following:
{
"type": "AudioPlayer.Play",
"playBehavior": "ENQUEUE",
"audioItem": {
"stream": {
"token": "Audio Playback",
"url": "http://www.audio.com/this/is/the/url/to/the/audio",
"offsetInMilliseconds": 0
}
}
}
ENQUEUE adds the specified stream to the end of the current stream queue. The offsetInMilliseconds key sets how far into the stream (in milliseconds) playback should begin.
When you nest this into the larger response JSON, it takes on the form of following:
{
"version": "1.0",
"sessionAttributes": {},
"response": {
"outputSpeech": {},
"card": {},
"reprompt": {},
"directives": [
{
"type": "AudioPlayer.Play",
"playBehavior": "ENQUEUE",
"audioItem": {
"stream": {
"token": "Audio Playback",
"url": "http://www.audio.com/this/is/the/url/to/the/audio",
"offsetInMilliseconds": 0
}
}
}
],
"shouldEndSession": true
}
}
There are a handful of other options to include in your audio directive. These can be found in the link I mentioned above.
I find it most beneficial to make a function where you can pass in given values to create the AudioPlayer directive JSON. For example, in python, this may look like the following:
def build_audio_directive(play_behavior, token, url, offset)
return {
"type": "AudioPlayer.Play",
"playBehavior": play_behavior,
"audioItem": {
"stream": {
"token": token,
"url": url,
"offsetInMilliseconds": offset
}
}
}
There are multiple ways to build up the response, but I find this way is the easiest for me to visualize.

Related

Firebase Cloud Firestore - Fail to write via REST API

This is not an authentication error, write is enabled on the database rules.
My cloud Firestore database looks like the picture below.
There is a COLLECTION called colA, inside it there is a DOCUMENT called docA, and inside it there are some fields (strings) stored.
On Postman, if I do GET https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, I do receive the following answer, and it is correct:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldB": {
"stringValue": "ABCD"
},
"fieldA": {
"stringValue": "888"
}
},
"createTime": "2020-01-31T16:48:26.859181Z",
"updateTime": "2020-02-05T19:21:49.654340Z"
}
Now, when I try to write a new field (fieldC) via POST https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, with JSON content:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldC": {
"stringValue": "1000"
}
}
}
After SEND, I receive this:
{
"error": {
"code": 400,
"message": "Document parent name \"projects/eletronica-ab6b1/databases/(default)/documents/colA\" lacks \"/\" at index 60.",
"status": "INVALID_ARGUMENT"
}
}
What I'm doing wrong? I really would like to write strings there via REST API.
Regards.
Updating a document is done with a PATCH request, according to the [reference documentation).
A POST request is used to create a new document in a collection, which probably explains the error you get: you're pointing to a document, but POST expects a collection path.

Include a custom field in every Wagtail API response

My company is running Wagtail headless, using only the API, to power parts of an existing web intranet. We'd like to include a customized "edit bar" at the top of every page in the main web application, which points to the "edit" page of the matching record in Wagtail. We're going to pass the current user's along with the request. Then we'd like to include a custom field in the Wagtail API response, for all requests which indicates that user's permission to edit that resource.
To illustrate, I'm looking to make a request like this:
http://localhost:32891/api/v2/page/?fields=place_id,location_slug&type=destination.DestinationPage&user_email=foo#bar.com
Which would result (in a perfect world) in a response like this:
{
"custom": {
"can_edit": True,
},
"meta": {
"total_count": 10
},
"items": [
{
"id": 1,
"title": "Test blog post",
"published_date": "2016-08-30",
},
]
}
The API indicates that you can include custom fields in the Page (or Image and Document), API response, but ideally I'd like for this object to be available for all "things" via our API. This means that if someone requests a document, I wouldn't have to manually return this field for each individual model.
I'm thinking it might be possible to override the behavior of the BaseAPIEndpoint?
Here's one way that we figured out how to do it. The "SecuredPagesAPIEndpoint" pages class already existed in our system.
class SecuredPagesAPIEndpoint(PagesAPIEndpoint):
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
def listing_view(self, request):
response = super().listing_view(request)
# create custom response object
# this object will contain any number of custom properties that we want to
# expose to consumers of this API
response.data['custom'] = {
'foo': 'BAR'
}
return response
and this is the resulting JSON:
{
"meta": {
"total_count": 1
},
"items": [
{
"id": 8,
"meta": {
"type": "destination.DestinationPage",
"detail_url": "http://localhost/api/v2/page/8/",
"html_url": "http://localhost/my-page-title/",
"slug": "my-page-title",
"first_published_at": "2019-02-19T17:15:13.952708Z"
},
"title": "My page title"
}
],
"custom": {
"FOO": 'BAR'
}
}

Alexa VideoApp.Launch directive - The target device does not support the specified directive

I am trying to use the VideoApp.Launch directive within my custom skill. Therefore I set the skill information global field for video app to true and added those required intents for video player.
Afterwards I'm started to test it with an example from this page
Before I added the Video directive alexa was simple returning the output content. But after adding this directory I'm getting the error: The target device does not support the specified directive. I couldn't find any documentation which addresses this issue. Is there a device setting which I missed?
Update: I tried it for the Display.RenderTemplate as well with the same outcome. Error: The target device does not support the specified directive. I set the required global fields to true for audio, render template and video.
What I checked so far is: msg.context.System.device.supportedInterfaces
"supportedInterfaces": {
"AudioPlayer": {}
}
I am using the echo. Why are here no other Interfaces available? How can I make them available?
My Code and Error Message are below.
/**
*
* main() will be invoked when you Run This Action
*
* #param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* #return The output of this action, which must be a JSON object.
*
*/
var main = function(msg) {
var response = {
version: "1.0",
response: {
outputSpeech: {
type: "PlainText",
text: "" + 'JSON.stringify(msg.request.intent)' //'.slots.questionContent.value'
},
"directives": [
{
"type": "VideoApp.Launch",
"videoItem":
{
"source": "https://www.example.com/video/sample-video-1.mp4",
"metadata": {
"title": "Title for Sample Video",
"subtitle": "Secondary Title for Sample Video"
}
}
}
],
"reprompt": null
}, "sessionAttributes": null
};
return {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: new Buffer(JSON.stringify(response)).toString("base64")
};
};
Error Message in Alexa History:
The problem is your device "Amazon Echo" does not have a display for the video. The "Amazon Echo Show" supports the following:
"supportedInterfaces": {
"Display": {},
"AudioPlayer": {},
"VideoApp": {}
}
More information here: https://developer.amazon.com/docs/custom-skills/best-practices-for-echo-show-skills.html#parse-supported-interfaces
Second, you should not have "sessionAttributes": null in the request. It is also written in the documentation.
Note: The shouldEndSession parameter must not be included in the
response, even if the value is set to null.
https://developer.amazon.com/de/docs/custom-skills/videoapp-interface-reference.html

How do I handle 'Yes'/'No' responses from the user in Custom Skill?

I am trying to build an alexa custom skill. I am facing an issue where I am trying to get Yes/No responses from the user for a question which the skill asks the user.
Alexa: Would you like to know the rules of the game?
User: <Can respond either Yes or No>
Based on the user response I would like to perform a specific action.
Here is my intent schema:
{
"intents": [
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "StartGame"
},
{
"intent": "GetRules"
}
]
}
Here are my sample utterances:
StartGame Begin the game
StartGame Start the game
GetRules What are the rules
GetRules Get the rules
GetRules Tell me the rules
GetRules Tell me the rules again
The question the skill asks the user is below:
Welcome to the game. Would you like me to tell you the rules?
Whenever I say "Yes", the StartGame intent is what is being triggered. (Same is the case for "No"). Alexa picks the intent as StartGame always. What is the best way to invoke "GetRules" intent. I want the user to just say Yes/No and not say "Get the rules".
Please let me know if this has been already answered/more information is needed.
You need to use AMAZON.YesIntent and AMAZON.NoIntent.
You can read about them here:.
Standard Built-in Intents.
https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/built-in-intent-ref/standard-intents
Please add below code in interaction model.
{
"name": "AMAZON.NoIntent",
"samples": []
},
{
"name": "AMAZON.YesIntent",
"samples": []
}
And provide your business logic for yes/no in your lambda.
'AMAZON.YesIntent': function () {
//business code
},
'AMAZON.NoIntent': function () {
//business code
}

Fetching Facebook Timeline posts using Facebook API

I'm facing following issues while fetching facebook user/pages/group timeline posts:
I'm not getting all information (photos urls, link, created_time, etc) in posts objects retrieved using this. Following is a sample response of this api:
[
{
"message": "this is going to be real fun https://localhost.com/N1AyEvZp",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-03T16:27:34+0000",
"id": "405944472923733_413853035466210"
},
{
"message": "this is going to be fun https://localhost.com/EJo1WvZp",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-03T16:14:41+0000",
"id": "405944472923733_413848848799962"
},
{
"message": "this is going to be some real funhttps://localhost.com/VyVKdWga",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"updated_time": "2015-09-02T15:45:08+0000",
"id": "405944472923733_413582785493235"
}
]
This response is missing the photo urls, links, captions, etc from the posts. Is there any different api for fetching those informations ? Also, if I directly hit the one of the post object /405944472923733_413582785493235 then I get following response:
{
"created_time": "2015-09-02T15:45:07+0000",
"message": "this is going to be some real funhttps://localhost.com/VyVKdWga",
"story": "Rajveer Singh added photos to XYZ Photos in My-group.",
"id": "405944472923733_413582785493235"
}
Though I get created_time in this response but pictures, urls, are still missing. I found this api deprecated. Is there any different api which can give me all the info ?
The above response is also missing comments and replies. On google search I found that we can get comments using /405944472923733_413582785493235/comments api but again that api doesn't mention the exact comments count. Also, the api doesn't give all the comments in a single api call. They have a pagination kind of thing. Can anyone tell me how can I get exact count of comments, replies to comments, and retrieve all the comments in a single api call. If we can't retrieve all the comments in a single go, then how can we use pagination ? I need to send all the comments related to a post to my front-end. with pagination, how can I achieve that ? Do I need to store the previous/next urls somewhere in front-end ? Following is a sample response of this:
{
"data": [
{
"id": "[post_id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T02:36:23+0000"
},
{
"id": "[id]",
"from": {
"name": "[name]",
"id": "[id]"
},
"message": "[message]",
"created_time": "2011-01-23T05:16:56+0000"
}
],
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTVRJeE5qWTRORGN5Tmpnd09qRTBOREl3T0RRd09URT0=",
"before": "WTI5dGJXVnVkRjlqZFhKemIzSTZOREUzTVRFNU16RTRORGN5T1RFMU9qRTBOREl3T0RRd05qZz0="
},
"previous": "previousUrl",
"next": "nextUrl"
}
How to get count of all the likes and shares of a post ? I simply want the count and doesn't want who actually likes/shared the post. How can I get that ? I found that using /likes gives a list of all those who liked the post but it doesn't give the count. Following is a sampple response of that:
{
"data": [
{
"id": "824565440992306"
}
],
"paging": {
"cursors": {
"after": "ODI0NTY1NDQwOTkyMzA2",
"before": "ODI0NTY1NDQwOTkyMzA2"
}
}
}
General Information:
I'm using Node.js Javascript SDK for hitting FB APIs.
I'm using correct access token, so that's not an issue for sure.
I have gone through this and this but didn't get any help from them.
I need all the information related to wall posts on my back-end so that I can send all data to my front-end for proper rendering. This is a screenshot of my front-end and all the information which I need in front-end.
Can anyone please try to clear my doubts ?
Also, if there is any optimized way of fetching all this information, then please do suggest. Your suggestions are welcome.

Resources