Alexa to ask user something after playback has finished - alexa

So before I even go into my issue, I've looked at this. Basically all I am trying to do is simply just play some audio, when the audio is finished, I just want Alexa to ask the user something. That's it. When I try to emit :ask I get the The following directives are not supported: Reponse may not contain an output speech, Response may not have shouldEndSession set to false
Okay, and the SO link I posted above is what I found after googling that. So is there honestly absolutely no way for Alexa to say/ask something after audio has finished?? If so, that is absolutely absurd, is there ANY workaround for that?
Here's my code for relevance:
'PlaybackFinished' : function() {
console.log('The stream comes to an end');
//here lets get the name, and start scenario 3.
this.emit('PostMissionRequest');
},
'PostMissionRequest': function() {
var db = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: "ALP-Infusion-Adventures",
Key: {
"UIUD": "1"
}
};
var self = this;
this.response.speak('Stream ended').audioPlayerStop();
db.get(params, function(err, data) {
if (err) {
...
} else {
console.log("GetItem succeeded! Results:", JSON.stringify(data, null, 2));
var res = data.Item;
self.response.speak('this is a test');
self.emit(':ask', `Nice job completing your mission, ${res.UName}! Would you like to plan your next mission?`)
self.emit(':responseReady');
}
});
},

According to the documentation, you can not, but you could enqueue an MP3 of the speech that you want Alexa to say. In your case, instead of this.response.speak('Stream ended') you could have an MP3 recording of that and ENQUEUE it in your PostMissionRequest handler

Related

MongoDB / Express / React - How to define the variable name which will be saved in the db

Im still new in coding and struggle on some basics.
I have to create a URL-Shortener with Express and MongoDB, additionally I use React for the frontent.
I have an input field and a submit button. The inputed URL will be sended by a POST request to the server.
(a console.log shows that this works fine)
Using "npm short-id"-package helps me to define an id for the shortUrl if the inputed url is accepted by "npm validid"- package.
Up to here, everything is fine.
Now, the "amateur-struggle" begins :)
I have learned the common pattern to save data in the mongoDB, example:
var createAndSaveUrl = function(done) {
var NEEDHELP = new Url({url: req.body.url, shortUrl: shortid.generate()});
NEEDHELP.save(function(err, data) {
if (err) return console.error(err);
done(null, data)
});
};
The "NEEDHELP" variable makes me go crazy, because I think I have to give it a unique name for the DB but dont know how to do that.
Someone can help me out?
var createAndSaveUrl = function(done) { var shortenedUrl= new Url({url: req.body.url, shortUrl: shortid.generate()});
shortenedUrl.save(function(err, data) {
if (err) return console.error(err);
done(null, data) }); };
I think this is enough.

Removing created records in e2e tests after all tests have run

I have been looking around for suitable ways to 'clean up' created records after tests are run using Protractor.
As an example, I have a test suite that currently runs tests on create and update screens, but there is currently no delete feature, however there is a delete end point I can hit against the backend API.
So the approach I have taken is to record the id of the created record so that in an afterAll I can then issue a request to perform a delete operation on the record.
For example:
beforeAll(function() {
loginView.login();
page.customerNav.click();
page.customerAddBtn.click();
page.createCustomer();
});
afterAll(function() {
helper.buildRequestOptions('DELETE', 'customers/'+createdCustomerId).then(function(options){
request(options, function(err, response){
if(response.statusCode === 200) {
console.log('Successfully deleted customer ID: '+ createdCustomerId);
loginView.logout();
} else {
console.log('A problem occurred when attempting to delete customer ID: '+ createdCustomerId);
console.log('status code - ' + response.statusCode);
console.log(err);
}
});
});
});
//it statements below...
Whilst this works, I am unsure whether this is a good or bad approach, and if the latter, what are the alternatives.
I'm doing this in order to prevent a whole load of dummy test records being added over time. I know you could just clear down the database between test runs, e.g. through a script or similar on say a CI server, but it's not something I\we have looked into further. Plus this approach seems on the face of it simpler, but again I am unsure about the practicalities of such an approach directly inside the test spec files.
Can anyone out there provide further comments\solutions?
Thanks
Well, for what it's worth I basically use that exact same approach. We have an endpoint that can reset data for a specific user based on ID, and I hit that in a beforeAll() block as well to reset the data to an expected state before every run (I could have done it afterAll as well, but sometimes people mess with the test accounts so I do beforeAll). So I simply grab the users ID and send the http request.
I can't really speak to the practicality of it, as it was simply a task that I accomplished and it worked perfectly for me so I saw no need for an alternative. Just wanted to let you know you are not alone in that approach :)
I'm curious if other people have alternative solutions.
The more robust solution is to mock your server with $httpBackend so you don't have to do actual calls to your API.
You can then configure server responses from your e2e test specs.
here's a fake server example :
angular.module('myModule')
.config(function($provide,$logProvider) {
$logProvider.debugEnabled(true);
})
.run(function($httpBackend,$log) {
var request = new RegExp('\/api\/route\\?some_query_param=([^&]*)');
$httpBackend.whenGET(request).respond(function(method, url, data) {
$log.debug(url);
// see http://stackoverflow.com/questions/24542465/angularjs-how-uri-components-are-encoded/29728653#29728653
function decode_param(param) {
return decodeURIComponent(param.
replace('#', '%40').
replace(':', '%3A').
replace('$', '%24').
replace(',', '%2C').
replace(';', '%3B').
replace('+', '%20'));
}
var params = url.match(request);
var some_query_param = decodeURIComponent(params[1]);
return [200,
{
someResponse...
}, {}];
});
});
Then load this script in your test environnement and your done.

send multiple responses to client via nodejs

i am using nodejs and i want to send back multiple responses to client.And my code is below
//addwork
var agenda = require('../../schedules/job-schedule.js')(config.db);
exports.addwork = function(req, res) {
var work = new Work(req.body);
work.user = req.user._id;
var user=req.user;
work.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
console.log('created work....'+work);
console.log('dateeeeeeeeeeeee'+work.created);
console.log('calling agenda job now, user is: '+ JSON.stringify(req.user));
console.log('supervisor-------------------------'+JSON.stringify(user.supervisor));
agenda.now('Work_To_Supervisior_Notify', {supervisor:user.supervisor,title:work.title,details:work.details});
res.jsonp(work);
res.send({message:'An email has been sent to ' + user.supervisor + ' with further instructions.'});
}
});
};`
//job-schedule.js
var Agenda = require("agenda");
var emailJob = require('./jobs/email-job.js');
module.exports = function(agendaDb) {
var agenda = new Agenda({db: { address: agendaDb}});
emailJob.sendWorkToSupervisiorEmail(agenda);
agenda.start();
return agenda;
}
//email-job.js
exports.sendWorkToSupervisiorEmail = function(agenda){
agenda.define('Work_To_Supervisior_Notify',{priority: 'high', concurrency: 10}, function(job, done){
console.log('Send works to supervisior ' + JSON.stringify(job.attrs.data.supervisor)+' ,title '+job.attrs.data.title+' ,details '+job.attrs.data.details);
var smtpTransport = nodemailer.createTransport(config.mailer.options);
var mailOptions = {
to: job.attrs.data.supervisor,
from: config.mailer.from,
subject: 'work done by user',
html: '<b>work title : '+job.attrs.data.title+' <br/>work details : '+job.attrs.data.details+'</b>'
};
smtpTransport.sendMail(mailOptions, function(err) {
if (!err) {
console.log('An email has been sent to ' + job.attrs.data.supervisor + ' with further instructions.');
res.send({message:'An email has been sent to ' + user.supervisor + ' with further instructions.'});
}
});
done();
})
}
Here i want response either from agenda or from res.send() message in addwork function
If i use res.send in addwork function it shows ERROR as "can't set headers after they sent".And if i use res.send message in sendWorkToSupervisiorEmail() it show ERROR as "there is no method send".I am new to nodejs please help me with solution
A http request only gets a single http response. Using http, you only get one response. Some options for you:
1) Wait for everything to finish before replying. Make sure each part creates a result, success or failure, and send the multiple responses at once. You would need some control flow library such as async or Promises to make sure everything responded at the same time. A good choice if all parts will happen "quickly", not good if your user is waiting "too long" for a response. (Those terms were in quotes, because they are application dependent).
2) Create some scheme where the first response tells how many other responses to wait for. Then you'd have a different HTTP request asking for the first additional message, and when that returns to your client, ask for the second additional message, and so on. This is a lot of coordination though, as you'd have to cache responses, or even try again if they were not done yet. Using a memory cache like redis (or similar) could fulfill the need to holding responses until ready, with a non-existent meaning 'not ready'
3) Use an eventing protocol, such as WebSockets, that can push messages from the server. This is a good choice, especially if you don't know how long some events would occur after the trigger. (You would not want to stall a HTTP request for tens of seconds waiting for 3 parts to complete - user will get bored, or quit, or re-submit.). Definitely check out the Primus library for this option. It can even serve the client-side script, which makes integration quick and easy.

Get the current browser name in Protractor test

I'm creating users in some test. Since it is connected to the backend and create real users I need fixtures. I was thinking of using the browser name to create unique user. However, It has proven to be quite difficult to get to it...
Anyone can point me in the right direction?
Another case of rubber ducking :)
The answer was actually quite simple.
in my onPrepare function I added the following function and it works flawlessly.
browser.getCapabilities().then(function (cap) {
browser.browserName = cap.caps_.browserName;
});
I can get access the name in my test using browser.browserName.
This has changed in version of protractor starting from 3.2 (selenium webdriver 2.52)
Now one should call:
browser.driver.getCapabilities().then(function(caps){
browser.browserName = caps.get('browserName');
}
If you want to avoid the a browser, you may want to do this:
it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {
browser.getCapabilities().then(function (capabilities) {
browserName = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function () {
console.log('Browser:', browserName, 'on platform', platform);
if (browserName === 'internet explorer') {
console.log('IE Was avoided for this test.');
} else {
basePage.email.sendKeys('bruno#test.com');
console.log('Mande el mail');
basePage.subscribe.click().then(function () {
basePage.confirmMessage('Contact already added to target campaign');
});
}
});
});

Understanding BackboneJS flow

I have been given a Project which is written entirely in Backbone.js, which I am supposed to change according to our specific needs. I have been studying Backbone.js for the past 2 weeks. I have changed the basic skeleton UI and a few of the features as needed. However I am trying to understand the flow of the code so that I can make further changes.
Specifically, I am trying to search some content on Youtube. I have a controller which uses a collection to specify the url and parse and return the response. The code is vast and I get lost where to look into after I get the response. I tried to look into views but it only has a div element set. Could someone help me to proceed. I wont be able to share the code here, but a general idea of where to look into might be useful.
Code Snippet
define([
'models/youtubeModelForSearch',
'coretv/config',
'libs/temp/pagedcollection',
'coretv/coretv'
],function( youtubeModelForSearch, Config, PagedCollection, CoreTV ) {
"use strict";
return PagedCollection.extend({
model: youtubeModelForSearch,
initialize: function() {
this.url = 'http://gdata.youtube.com/feeds/api/videos/?v=2&alt=json&max-results=20';
},
fetch: function(options) {
if (options === undefined) options = {};
if (options.data === undefined) options.data = {};
//options.data.cmdc = Config.getCMDCHost();
//CoreTV.applyAccessToken(options);
PagedCollection.prototype.fetch.call(this, options);
},
parse: function(response) {
var temp = response.feed
/*temp["total"] = 20;
temp["start"] = 0;
temp["count"] = 10; */
console.log(temp);
return temp.entry;
},
inputChangeFetch: function(query) {
this.resetAll();
if(query) {
this.options.data.q = query;
// this.options.data.region = Config.api.region;
//this.options.data.catalogueId = Config.api.catalogueId;
this.setPosition(0);
}
}
});
});
Let's assume your collection endpoint is correctly set and working. When you want to get the data from the server you can call .fetch() on you collection.
When you do this, it will trigger an request event. Your views or anybody else can listen to it to perform any action.
When the data arrives from the server, your parse function is called, it is set using set or reset, depending the options you passed along fetch(). This will trigger any event related to the set/reset (see the documentation). During set/reset, the data retrieved from your server will be parsed using parse (you can skip it, passing { parse: false }.
Right after that, if you passed any success callback to your fetch, it will be called with (collection, response, options) as parameters.
And, finally, it will trigger a sync event.
If your server does not respond, it will trigger an error event instead of all this.
Hope, I've helped.

Resources