Skip to content

Commit

Permalink
Merge pull request #44 from Accenture/detect-SSML-in-texts
Browse files Browse the repository at this point in the history
Detect ssml tag <speak>in response texts
  • Loading branch information
misyak committed Dec 19, 2016
2 parents 60f78ff + bda2be8 commit d2a0c22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/handle-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ const createResponse = (options, slots, attrs, app) => {
*/
const createOutputSpeechObject = (text, ssml) => {
let outputSpeech = {};
if (!ssml) {
outputSpeech.type = 'PlainText';
outputSpeech.text = text;
} else {
if (text.includes('<speak>') || ssml) {
outputSpeech.type = 'SSML';
outputSpeech.ssml = text;
} else {
outputSpeech.type = 'PlainText';
outputSpeech.text = text;
}
return outputSpeech;
};
12 changes: 11 additions & 1 deletion test/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ describe('basic app handler', () => {
});
});

it('should handle IntentC request with SSML outputSpeech type', (done) => {
const request = alexia.createIntentRequest('IntentC', null, attrs, false, 'appId1');

app.handle(request, (response) => {
attrs = response.sessionAttributes;
expect(response.response.outputSpeech).to.deep.equal({type: 'SSML', ssml: '<speak>Hi</speak>'});
done();
});
});

it('should handle async intent', (done) => {
const request = alexia.createIntentRequest(intents[11].name, null, null, false, 'appId1');
const request = alexia.createIntentRequest(intents[12].name, null, null, false, 'appId1');

app.handle(request, (response) => {
expect(response.response.outputSpeech.text).equal('I just did stuff asynchronously. Thank you for this opportunity');
Expand Down
2 changes: 2 additions & 0 deletions test/mock/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.intentSchema = {
{intent: 'AMAZON.CancelIntent'},
{intent: 'IntentA'},
{intent: 'IntentB'},
{intent: 'IntentC'},
{intent: 'e'},
{intent: 'AnotherCardIntentSample'},
{intent: 'IntentWithoutUtterances'}
Expand All @@ -39,6 +40,7 @@ exports.utterances = [
'AMAZON.HelpIntent yup',
'IntentA another utterance',
'IntentB another utterance',
'IntentC another utterance',
'e async response',
'AnotherCardIntentSample card intent'
];
Expand Down
6 changes: 6 additions & 0 deletions test/test-apps/basic-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ app.intent('IntentB', 'another utterance', (slots, attrs) => {
return `attribute value is ${attrs.yes}`;
});

app.intent('IntentC', 'another utterance', (slots, attrs) => {
return {
text: '<speak>Hi</speak>'
};
});

app.intent(null, 'async response', (slots, attrs, data, done) => {
setTimeout(() => {
done('I just did stuff asynchronously. Thank you for this opportunity');
Expand Down

0 comments on commit d2a0c22

Please sign in to comment.