Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registerCommand Method: annayang #61

Open
sharmmoh1983 opened this issue Sep 14, 2017 · 3 comments
Open

registerCommand Method: annayang #61

sharmmoh1983 opened this issue Sep 14, 2017 · 3 comments

Comments

@sharmmoh1983
Copy link

sharmmoh1983 commented Sep 14, 2017

Hey

I am trying to add commands using Sonus.annyang.addCommands(commands);

const commands = {
'hello': function () {
console.log('You will obey');
},
'(give me) :flavor ice cream': function (flavor) {
console.log('Fetching some ' + flavor + ' ice ceam for you sr')
},
'turn (the)(lights) :state (the)(lights)': function (state) {
console.log('Turning the lights', (state == 'on') ? state : 'off')
}
}

This is working fine. But in my one of my application, I am not able to create above commands JSON object dynamically or static way because of some limitation so wanted to have a method in lib/annyang-core to add Commands to annyang:

file : lib/annyang-core.js

method : registerCommand(phrase , callback function)

which will add commands one by one to annayang

@evancohen
Copy link
Owner

Pretty sure you can use the addCommands() function multiple time with a single command object. They will not be overwritten. For example

const command1 = {
  'hello': function () {
    console.log('You will obey');
  }
}

Sonus.annyang.addCommands(command1)

const command2 = {
  '(give me) :flavor ice cream': function (flavor) {
    console.log('Fetching some ' + flavor + ' ice ceam for you sr')
  }
}

Sonus.annyang.addCommands(command2)

Does that satisfy what you're trying to accomplish?

@sharmmoh1983
Copy link
Author

No .. The issue is command1 structure is not getting created and added properly because of explicit callback function in json
I want to explicitly send phrase and callback in a function to add the command

@sharmmoh1983
Copy link
Author

That will help me to add commands at runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants