Skip to content

Commit

Permalink
Merge pull request #16 from Telefonica/fix-attachments#15
Browse files Browse the repository at this point in the history
[[FIX]] Attachments are removed when keyboards are moved
  • Loading branch information
JoseAntonioRodriguez authored Dec 19, 2016
2 parents ebc1d86 + 8ed7ca9 commit ed8548a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/middlewares/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ export default function factory(): BotBuilder.IMiddlewareMap {
}

bingSpeechClient.synthesize(event.text)
.then(response => storage.upload(streamifier.createReadStream(response.wave)))
.then(response => {
logger.debug('Bing Speech synthesize succeeded');
return storage.upload(streamifier.createReadStream(response.wave));
})
.then(url => {
logger.info({url: url}, 'Audio response uploaded');
event.attachments = event.attachments || [];
event.attachments.push({
contentType: 'audio/wave',
Expand Down
5 changes: 4 additions & 1 deletion src/middlewares/directline-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import * as BotBuilder from 'botbuilder';
import { Channel } from '../botbuilder-ext';
import * as logger from 'logops';

/**
* Look for outgoing messages whose channel is DirectLine and carry some attachment whose contentType
Expand All @@ -34,11 +35,13 @@ export default {
// Pick the attachment with contentType 'application/vnd.microsoft.keyboard'
let choicesIndex = message.attachments
.findIndex(attachment => attachment.contentType === 'application/vnd.microsoft.keyboard');
logger.debug('Found attachment of type Keyboard on index %d', choicesIndex);
if (choicesIndex !== -1) {
// Move the attachment containing the choices to the channelData
let choices = message.attachments.splice(choicesIndex);
let choices = message.attachments.splice(choicesIndex, 1);
message.sourceEvent = message.sourceEvent || {};
message.sourceEvent.choices = choices[0];
logger.info('Keyboard moved from attachments to channelData');
}
}
}
Expand Down

0 comments on commit ed8548a

Please sign in to comment.