alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

Patch for directive Dialog.Delegate #372

Open Nicky31 opened 5 years ago

Nicky31 commented 5 years ago

Hi,

After a few hours trying to figure out why alexa raised an error on my directive response instead of speeching configured prompt for missing slots, It turned out that alexa-app includes outputSpeech object in its reply, which seems exactly to be the problem. Given a Dialog.Delegate directive telling to rely only on model dialogs, Alexa expect not to have outputSpeech attribute besides this directive.

So I patched this with an ugly delete before replying, but I guess fixing your response construction might benefits to some other users :-)

The monkey patch, within any alexa-app handler getting response object:

            if (response.response.response.outputSpeech) {
                delete response.response.response.outputSpeech
            }
lazerwalker commented 5 years ago

Hi! Thanks for this!

If I'm understanding you correctly, the correct fix for this is to apply that (making sure there's no outputSpeech in the underlying Alexa response) in the situation where there's a Dialog.Delegate directive to rely only on model dialogs.

If that's the case, it sounds to me like that's a great case to add this into the codebase itself, with the appropriate logic to make sure we only remove outputSpeech in that specific scenario.

Any interest in contributing a pull request?

Nicky31 commented 5 years ago

Hi, After taking a look at your codebase to fix this point, I've figured out outputSpeech is not initialized on the construction of responses but it is in clear() method. Any reason for this ? Why not simply delete this attribute ? Looks a bit weird. I guess outputSpeech deletion (instead of rewrite) in clear() would do the trick, but i'm wondering if it would break anything.