Reputation: 10030
I'm trying to build an ASK (Alexa Skill Kit) app to basically read off messages as they come in.
The code I have attempting to test this so far is:
function handleObserveFlowIntentRequest(intent, session, response) {
var callback = function (message) {
response.tell({
speech: message,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
});
};
callback("One Observe Flow");
callback("Two Observe Flow");
}
I'm only able to get the response from the first callback outputting "One Observe Flow"
eventually I want to basically do something like this:
function handleObserveFlowIntentRequest(intent, session, response) {
var callback = function (message) {
response.tell({
speech: message,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
});
};
var jsonStream = new EventSource(::myApiUrl::);
jsonStream.onmessage = function (e) {
callback(e.data.message);
}
}
Upvotes: 2
Views: 975
Reputation: 713
This is way late but maybe will be of use to others. While you can't do it with ASK, you could with AVS. It would mean building your own Echo with a raspberry pi or such, but it would do what you are looking for. Instead of it being a constant open stream, you would trigger a discrete response for each event that occurs. You can check out this hackster project I did which does something similar. In my case, the code running on the RPI waits for an event. When an IOT button is pressed, Alexa speaks a corresponding response.
Upvotes: -1
Reputation: 6651
What you are trying to do is not possible in the ASK platform at this time.
It is not possible to have Alexa say something without first being prompted. Alexa is conversational and isn't able to interrupt the user.
While it may look like what you want to do is possible in code based on the asynchronous nature of node.js, your skill is being called synchronously by Amazon based on a given Intent and you are simply providing a response. ASK does not provide a mechanism for you to push something to Alexa for it to say.
This means that you have to form your entire response before Alexa will actually say anything. To reiterate, this is because Amazon is calling your skill with an Intent and expecting a response. After you return that response using response.tell you can't make Alexa say anything else until you receive another Intent request from Amazon.
Upvotes: 4