NumminorihSF / ami-io

Use node.js or io.js to manage Asterisk through AMI
MIT License
30 stars 16 forks source link

Problem to using Multiple Variables on Originate Action #9

Closed orlandosantos closed 7 years ago

orlandosantos commented 7 years ago

Hi,

First of all I would like to thank you for your contribution.

I'm trying to use Originate action with multiple Variables but only the last Variable has been sent to asterisk. Please find below a sample.

var action = new AmiIo.Action.Originate(); action.MaxRetries = 2; action.RetryTime = 60; action.WaitTime = 30; action.Priority = 1; action.CallerID = 'Test <9000>'; action.Channel = 'local/9001@test/n'; action.Context = 'Autodial'; action.Exten = '9001'; action.Variable = 'Hostname="test hostname"'; action.Variable = 'Description="test description"'; action.Async = true; action.WaitEvent = true;

Note the result only has the last Variable;

Send: Originate { variables: {}, id: 2, ActionID: 2, Action: 'Originate', MaxRetries: 2, RetryTime: 60, WaitTime: 30, Priority: 1, CallerID: 'Vicci <9000>', Channel: 'local/9001@test/n', Context: 'Autodial', Exten: '9001', Variable: 'Description="test description"', Async: true, WaitEvent: true }

Could you please verify?

Thanks,

Orlando

NumminorihSF commented 7 years ago

Hi. Thanks for feedback. In your example you overwrite action.Variable so it will not really works as you want. I found that I didn't document this feature, so I update README to describe work with Variables.

If you need send some variables to AMI, use action.variables object like this:

    var action = new amiio.Action.SomeAction();
    action.variables.VariableA = 1;
    action.variables.VariableB = 2;
    action.variables.VariableC = 3;

Or you can do it like this:

    var action = new amiio.Action.SomeAction();
    action.variables = {
      VariableA: 1,
      VariableB: 2,
      VariableC: 3
    };

So, your code should be like this:

var action = new AmiIo.Action.Originate();
action.MaxRetries = 2;
action.RetryTime = 60;
action.WaitTime = 30;
action.Priority = 1;
action.CallerID = 'Test <9000>';
action.Channel = 'local/9001@test/n';
action.Context = 'Autodial';
action.Exten = '9001';
action.variables.Hostname = "test hostname";
action.variables.Description = "test description";
action.Async = true;
action.WaitEvent = true;
orlandosantos commented 7 years ago

It worked! Thank you very much for your help!