Giter Club home page Giter Club logo

agi-node's Introduction

Getting Started

1. Usage

npm install --save agi-node
var AGIServer = require('agi-node').AGIServer;
//var AsyncAGIServer = require('agi-node').AsyncAGIServer;
//var conn = new require('asterisk-manager')(5038, 'localhost', 'asterisk', 'astpass', true);

function fakeCallback(param, callback) {
  setTimeout(function () {
    callback(null, param);
  }, 2000);
}

function testScript(channel) {
  console.log('Script got call %s -> %s', channel.request.callerid, channel.request.extension);

  var answerReply = channel.answer();
  console.log('ANSWER', answerReply);

  console.log('CHANNEL STATUS', channel.channelStatus());
  console.log('GET UNIQUEID', channel.getVariable('UNIQUEID'));
  console.log('GET JUNK', channel.getVariable('JUNK'));

  console.log('beeping in 2 seconds');
  channel.streamFile(fakeCallback.sync(null, 'beep'));


  console.log('PLAYBACK', channel.streamFile('conf-adminmenu'));
  console.log('PLAYBACK', channel.streamFile('conf-adminmenu'));
}

/* Async AGI Server */
// conn is an asterisk-manager connection
//var server = new AsyncAGIServer(script, conn);

/* AGI Server */
var server = new AGIServer(testScript, 4573);
  • AGIServer constructor receives two parameters: a mapper and a port. If the mapper is a function it will execute that as an AGI script. If it is an object it maps script names from AGI URL to generator functions. Example: {hello: helloScript} will map agi://agi_host/hello to helloScript. The port is the AGI standard listening port (default 4573)
  • AsyncAGIServer receives two parameters: a mapper and an AMI connection (established through asterisk-manager)
  • The script should exit at the very end. That means that all async operations (e.g. database lookups) need to be done using sync library. This is a dependency of agi-node and the script is executed inside a fiber, so callbacks can be put in "sync" mode (see fakeCallback example above and sync library itself at https://www.npmjs.com/package/sync).

2. Channel API

2.1 Channel.request

This property is an object that maps all the AGI initialization variable without the agi_ prefix (e.g. agi_calleridname becomes channel.request.calleridname). Here's a list of all of these variables:

  • agi_request - The filename of your script
  • agi_channel - The originating channel (your phone)
  • agi_language - The language code (e.g. "en")
  • agi_type - The originating channel type (e.g. "SIP" or "ZAP")
  • agi_uniqueid - A unique ID for the call
  • agi_version - The version of Asterisk (since Asterisk 1.6)
  • agi_callerid - The caller ID number (or "unknown")
  • agi_calleridname - The caller ID name (or "unknown")
  • agi_callingpres - The presentation for the callerid in a ZAP channel
  • agi_callingani2 - The number which is defined in ANI2 see Asterisk Detailed Variable List (only for PRI Channels)
  • agi_callington - The type of number used in PRI Channels see Asterisk Detailed Variable List
  • agi_callingtns - An optional 4 digit number (Transit Network Selector) used in PRI Channels see Asterisk Detailed Variable List
  • agi_dnid - The dialed number id (or "unknown")
  • agi_rdnis - The referring DNIS number (or "unknown")
  • agi_context - Origin context in extensions.conf
  • agi_extension - The called number
  • agi_priority - The priority it was executed as in the dial plan
  • agi_enhanced - The flag value is 1.0 if started as an EAGI script, 0.0 otherwise
  • agi_accountcode - Account code of the origin channel
  • agi_threadid - Thread ID of the AGI script (since Asterisk 1.6)

2.2 Channel methods

  • answer()

Answers the channel

  • channelStatus()

Returns the current channel status (see http://www.voip-info.org/wiki/view/channel+status)

  • continueAt(context, extension, priority)

Sets the point in the dialplan to continue the call after the AGI script is done. extension is optional and, if missing, is set the current channel extension. priority is optional and, if missing, is set to 1.

  • exec(applicationName, applicationParameters)

Executes the requested dialplan application with parameters

  • getData(file, timeout, maxDigits)

Reads DTMF input from user. Plays the file prompt. Times out at timeout milliseconds and allows up to maxDigits to be read. It can be ended with #.

  • getVariable(variableName)

Reads the specified variable value on the current channel. Returns null if variable does not exist.

  • noop()

Does nothing.

  • recordFile(file, format, escapeDigits, timeout, silenceSeconds, beep)

Records the current channel in file using format. Recording can be stopped using one of the escapeDigits or after silenceSeconds. If beep is true, a beep sound is played before recording is started.

  • setContext(context)

Sets the context to continue at after leaving the script.

  • setExtension(extension)

Sets the extension to continue at after leaving the script.

  • setPriority(priority)

Sets the priority to continue at after leaving the script.

  • setVariable(variable, value)

Sets the specified variable to the desired value.

  • streamFile(file, escapeDigits)

Plays the specified file. Playback can be stopped using one of the (optional) escapeDigits.

  • hangup()

Hangs up the current channel.

LICENSE

Copyright (c) 2015 Alexandru Pirvulescu [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

agi-node's People

Contributors

namtzigla avatar nicolascb avatar schwarsi avatar sigxcpu76 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agi-node's Issues

Can't select specific function inside script

Hi,

the script works as expected, but how can i decide, which function inside to call? Example:

I've got the extension calls:

exten => 1234,n,agi(agi://127.0.0.1/submitgs);
exten => 1234,n,agi(agi://127.0.0.1/receivetts);

And now I want the node.js - File to listen on port 4573 and execute either function submitgs or receivetts - but how?

If I write:

var server = new AGIServer(script, 4573);

script isnt found and if I write one of the functions, only this one is executed?

Thank you for your help!

Installation Issues

Hello. Try to install with command:
npm i agi-node -DE
and get a lot of errors. Entire log a very big, below the end part. I also ran sudo apt-get install g++ build-essential

Distributor ID:	Debian
Description:	Debian GNU/Linux 9.9 (stretch)
Release:	9.9
Codename:	stretch

Specific version of node needed ? What I miss ?
Thanks!


../src/fibers.cc: In member function ‘void Fiber::UnwindStack()’:
../src/fibers.cc:546:4: error: ‘Handle’ was not declared in this scope
    Handle<Value> zombie_exception = Exception::Error(uni::NewLatin1String(isolate, "This Fiber is a zombie"));
    ^~~~~~
../src/fibers.cc:546:16: error: expected primary-expression before ‘>’ token
    Handle<Value> zombie_exception = Exception::Error(uni::NewLatin1String(isolate, "This Fiber is a zombie"));
                ^
../src/fibers.cc:546:54: error: ‘NewLatin1String’ is not a member of ‘uni’
    Handle<Value> zombie_exception = Exception::Error(uni::NewLatin1String(isolate, "This Fiber is a zombie"));
                                                      ^~~
../src/fibers.cc:547:64: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::Value>&, v8::Persistent<v8::Value>&)’
    uni::Reset(isolate, this->zombie_exception, zombie_exception);
                                                                ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:547:48: note:   cannot convert ‘((Fiber*)this)->Fiber::zombie_exception’ (type ‘v8::Persistent<v8::Value>’) to type ‘int’
    uni::Reset(isolate, this->zombie_exception, zombie_exception);
                                                ^~~~~~~~~~~~~~~~
../src/fibers.cc:548:49: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::Value>&, v8::Persistent<v8::Value>&)’
    uni::Reset(isolate, yielded, zombie_exception);
                                                 ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:548:33: note:   cannot convert ‘((Fiber*)this)->Fiber::zombie_exception’ (type ‘v8::Persistent<v8::Value>’) to type ‘int’
    uni::Reset(isolate, yielded, zombie_exception);
                                 ^~~~~~~~~~~~~~~~
../src/fibers.cc:561:41: error: ‘Undefined’ is not a member of ‘uni’
     uni::Reset<Value>(isolate, yielded, uni::Undefined(isolate));
                                         ^~~
../src/fibers.cc:561:41: note: suggested alternatives:
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:11272:18: note:   ‘v8::Undefined’
 Local<Primitive> Undefined(Isolate* isolate) {
                  ^~~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:11272:18: note:   ‘v8::Undefined’
../src/fibers.cc: In static member function ‘static void Fiber::RunFiber(void**)’:
../src/fibers.cc:621:14: error: no matching function for call to ‘v8::TryCatch::TryCatch()’
     TryCatch try_catch;
              ^~~~~~~~~
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:9473:12: note: candidate: v8::TryCatch::TryCatch(v8::Isolate*)
   explicit TryCatch(Isolate* isolate);
            ^~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:9473:12: note:   candidate expects 1 argument, 0 provided
../src/fibers.cc:623:5: error: ‘Handle’ was not declared in this scope
     Handle<Context> v8_context = uni::Deref(that.isolate, that.v8_context);
     ^~~~~~
../src/fibers.cc:623:19: error: expected primary-expression before ‘>’ token
     Handle<Context> v8_context = uni::Deref(that.isolate, that.v8_context);
                   ^
../src/fibers.cc:623:21: error: invalid use of member ‘Fiber::v8_context’ in static member function
     Handle<Context> v8_context = uni::Deref(that.isolate, that.v8_context);
                     ^~~~~~~~~~
../src/fibers.cc:308:23: note: declared here
   Persistent<Context> v8_context;
                       ^~~~~~~~~~
../src/fibers.cc:623:34: error: ‘Deref’ is not a member of ‘uni’
     Handle<Context> v8_context = uni::Deref(that.isolate, that.v8_context);
                                  ^~~
../src/fibers.cc:624:5: error: invalid use of member ‘Fiber::v8_context’ in static member function
     v8_context->Enter();
     ^~~~~~~~~~
../src/fibers.cc:308:23: note: declared here
   Persistent<Context> v8_context;
                       ^~~~~~~~~~
../src/fibers.cc:628:21: error: ‘NewLatin1String’ is not a member of ‘uni’
     Script::Compile(uni::NewLatin1String(that.isolate, "void 0;"));
                     ^~~
../src/fibers.cc:630:17: error: expected primary-expression before ‘>’ token
     Handle<Value> yielded;
                 ^
../src/fibers.cc:630:19: error: invalid use of member ‘Fiber::yielded’ in static member function
     Handle<Value> yielded;
                   ^~~~~~~
../src/fibers.cc:310:21: note: declared here
   Persistent<Value> yielded;
                     ^~~~~~~
../src/fibers.cc:632:18: error: expected primary-expression before ‘>’ token
      Handle<Value> argv[1] = { (*args)[0] };
                  ^
../src/fibers.cc:632:20: error: ‘argv’ was not declared in this scope
      Handle<Value> argv[1] = { (*args)[0] };
                    ^~~~
../src/fibers.cc:633:6: error: invalid use of member ‘Fiber::yielded’ in static member function
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 1, argv);
      ^~~~~~~
../src/fibers.cc:310:21: note: declared here
   Persistent<Value> yielded;
                     ^~~~~~~
../src/fibers.cc:633:16: error: ‘Deref’ is not a member of ‘uni’
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 1, argv);
                ^~~
../src/fibers.cc:633:56: error: invalid use of member ‘Fiber::v8_context’ in static member function
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 1, argv);
                                                        ^~~~~~~~~~
../src/fibers.cc:308:23: note: declared here
   Persistent<Context> v8_context;
                       ^~~~~~~~~~
../src/fibers.cc:635:6: error: invalid use of member ‘Fiber::yielded’ in static member function
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 0, NULL);
      ^~~~~~~
../src/fibers.cc:310:21: note: declared here
   Persistent<Value> yielded;
                     ^~~~~~~
../src/fibers.cc:635:16: error: ‘Deref’ is not a member of ‘uni’
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 0, NULL);
                ^~~
../src/fibers.cc:635:56: error: invalid use of member ‘Fiber::v8_context’ in static member function
      yielded = uni::Deref(that.isolate, that.cb)->Call(v8_context->Global(), 0, NULL);
                                                        ^~~~~~~~~~
../src/fibers.cc:308:23: note: declared here
   Persistent<Context> v8_context;
                       ^~~~~~~~~~
../src/fibers.cc:639:66: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::Value>&, v8::Local<v8::Value>)’
      uni::Reset(that.isolate, that.yielded, try_catch.Exception());
                                                                  ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:639:64: note:   cannot convert ‘try_catch.v8::TryCatch::Exception()’ (type ‘v8::Local<v8::Value>’) to type ‘int’
      uni::Reset(that.isolate, that.yielded, try_catch.Exception());
                                             ~~~~~~~~~~~~~~~~~~~^~
../src/fibers.cc:641:45: error: ‘Deref’ is not a member of ‘uni’
      if (that.zombie && !that.resetting && !uni::Deref(that.isolate, that.yielded)->StrictEquals(uni::Deref(that.isolate, that.zombie_exception))) {
                                             ^~~
../src/fibers.cc:641:98: error: ‘Deref’ is not a member of ‘uni’
      if (that.zombie && !that.resetting && !uni::Deref(that.isolate, that.yielded)->StrictEquals(uni::Deref(that.isolate, that.zombie_exception))) {
                                                                                                  ^~~
../src/fibers.cc:643:66: error: no matching function for call to ‘v8::TryCatch::StackTrace()’
       uni::Reset(that.isolate, fatal_stack, try_catch.StackTrace());
                                                                  ^
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:9530:43: note: candidate: v8::MaybeLocal<v8::Value> v8::TryCatch::StackTrace(v8::Local<v8::Context>) const
   V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
                                           ^~~~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:9530:43: note:   candidate expects 1 argument, 0 provided
../src/fibers.cc:646:45: error: invalid use of member ‘Fiber::yielded’ in static member function
      uni::Reset(that.isolate, that.yielded, yielded);
                                             ^~~~~~~
../src/fibers.cc:310:21: note: declared here
   Persistent<Value> yielded;
                     ^~~~~~~
../src/fibers.cc:661:5: error: invalid use of member ‘Fiber::v8_context’ in static member function
     v8_context->Exit();
     ^~~~~~~~~~
../src/fibers.cc:308:23: note: declared here
   Persistent<Context> v8_context;
                       ^~~~~~~~~~
../src/fibers.cc: In static member function ‘static uni::FunctionType Fiber::Yield_(const Arguments&)’:
../src/fibers.cc:10:40: error: ‘ThrowException’ is not a member of ‘uni’
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                        ^
../src/fibers.cc:676:5: note: in expansion of macro ‘THROW’
     THROW(Exception::Error, "yield() called with no fiber running");
     ^~~~~
../src/fibers.cc:10:85: error: ‘NewLatin1String’ is not a member of ‘uni’
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                                                                     ^
../src/fibers.cc:676:5: note: in expansion of macro ‘THROW’
     THROW(Exception::Error, "yield() called with no fiber running");
     ^~~~~
../src/fibers.cc:10:139: error: return-statement with a value, in function returning 'void' [-fpermissive]
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                                                                                                                           ^
../src/fibers.cc:676:5: note: in expansion of macro ‘THROW’
     THROW(Exception::Error, "yield() called with no fiber running");
     ^~~~~
../src/fibers.cc:682:24: error: ‘ThrowException’ is not a member of ‘uni’
     return uni::Return(uni::ThrowException(that.isolate, uni::Deref(that.isolate, that.zombie_exception)), args);
                        ^~~
../src/fibers.cc:682:58: error: ‘Deref’ is not a member of ‘uni’
     return uni::Return(uni::ThrowException(that.isolate, uni::Deref(that.isolate, that.zombie_exception)), args);
                                                          ^~~
../src/fibers.cc:682:112: error: return-statement with a value, in function returning 'void' [-fpermissive]
     return uni::Return(uni::ThrowException(that.isolate, uni::Deref(that.isolate, that.zombie_exception)), args);
                                                                                                                ^
../src/fibers.cc:684:74: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::Value>&, v8::Local<v8::Primitive>)’
     uni::Reset<Value>(that.isolate, that.yielded, Undefined(that.isolate));
                                                                          ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:684:60: note:   cannot convert ‘v8::Undefined(that.Fiber::isolate)’ (type ‘v8::Local<v8::Primitive>’) to type ‘int’
     uni::Reset<Value>(that.isolate, that.yielded, Undefined(that.isolate));
                                                   ~~~~~~~~~^~~~~~~~~~~~~~
../src/fibers.cc:686:51: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::Value>&, v8::Local<v8::Value>)’
     uni::Reset(that.isolate, that.yielded, args[0]);
                                                   ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:686:50: note:   cannot convert ‘(& args)->v8::FunctionCallbackInfo<T>::operator[]<v8::Value>(0)’ (type ‘v8::Local<v8::Value>’) to type ‘int’
     uni::Reset(that.isolate, that.yielded, args[0]);
                                            ~~~~~~^
../src/fibers.cc:10:40: error: ‘ThrowException’ is not a member of ‘uni’
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                        ^
../src/fibers.cc:688:5: note: in expansion of macro ‘THROW’
     THROW(Exception::TypeError, "yield() expects 1 or no arguments");
     ^~~~~
../src/fibers.cc:10:85: error: ‘NewLatin1String’ is not a member of ‘uni’
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                                                                     ^
../src/fibers.cc:688:5: note: in expansion of macro ‘THROW’
     THROW(Exception::TypeError, "yield() expects 1 or no arguments");
     ^~~~~
../src/fibers.cc:10:139: error: return-statement with a value, in function returning 'void' [-fpermissive]
 #define THROW(x, m) return uni::Return(uni::ThrowException(Isolate::GetCurrent(), x(uni::NewLatin1String(Isolate::GetCurrent(), m))), args)
                                                                                                                                           ^
../src/fibers.cc:688:5: note: in expansion of macro ‘THROW’
     THROW(Exception::TypeError, "yield() expects 1 or no arguments");
     ^~~~~
../src/fibers.cc:711:28: error: ‘class Fiber’ has no member named ‘ReturnYielded’
    return uni::Return(that.ReturnYielded(), args);
                            ^~~~~~~~~~~~~
../src/fibers.cc:711:49: error: return-statement with a value, in function returning 'void' [-fpermissive]
    return uni::Return(that.ReturnYielded(), args);
                                                 ^
../src/fibers.cc: In static member function ‘static uni::FunctionType Fiber::GetStarted(v8::Local<v8::String>, const GetterCallbackInfo&)’:
../src/fibers.cc:719:24: error: ‘Undefined’ is not a member of ‘uni’
     return uni::Return(uni::Undefined(Isolate::GetCurrent()), info);
                        ^~~
../src/fibers.cc:719:24: note: suggested alternatives:
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:304:27: note:   ‘v8::Undefined’
   friend Local<Primitive> Undefined(Isolate* isolate);
                           ^~~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:304:27: note:   ‘v8::Undefined’
../src/fibers.cc:719:67: error: return-statement with a value, in function returning 'void' [-fpermissive]
     return uni::Return(uni::Undefined(Isolate::GetCurrent()), info);
                                                                   ^
../src/fibers.cc:721:36: error: no match for call to ‘(Fiber) (v8::Local<v8::Object>)’
    Fiber& that = Unwrap(info.This());
                                    ^
../src/fibers.cc:722:23: error: ‘NewBoolean’ is not a member of ‘uni’
    return uni::Return(uni::NewBoolean(that.isolate, that.started), info);
                       ^~~
../src/fibers.cc:722:72: error: return-statement with a value, in function returning 'void' [-fpermissive]
    return uni::Return(uni::NewBoolean(that.isolate, that.started), info);
                                                                        ^
../src/fibers.cc: In static member function ‘static uni::FunctionType Fiber::GetCurrent(v8::Local<v8::String>, const GetterCallbackInfo&)’:
../src/fibers.cc:729:24: error: ‘Undefined’ is not a member of ‘uni’
     return uni::Return(uni::Undefined(Isolate::GetCurrent()), info);
                        ^~~
../src/fibers.cc:729:24: note: suggested alternatives:
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:304:27: note:   ‘v8::Undefined’
   friend Local<Primitive> Undefined(Isolate* isolate);
                           ^~~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:304:27: note:   ‘v8::Undefined’
../src/fibers.cc:729:67: error: return-statement with a value, in function returning 'void' [-fpermissive]
     return uni::Return(uni::Undefined(Isolate::GetCurrent()), info);
                                                                   ^
../src/fibers.cc: In static member function ‘static uni::FunctionType Fiber::GetPoolSize(v8::Local<v8::String>, const GetterCallbackInfo&)’:
../src/fibers.cc:737:23: error: ‘NewNumber’ is not a member of ‘uni’
    return uni::Return(uni::NewNumber(Isolate::GetCurrent(), Coroutine::pool_size), info);
                       ^~~
../src/fibers.cc:737:88: error: return-statement with a value, in function returning 'void' [-fpermissive]
    return uni::Return(uni::NewNumber(Isolate::GetCurrent(), Coroutine::pool_size), info);
                                                                                        ^
../src/fibers.cc: In static member function ‘static void Fiber::SetPoolSize(v8::Local<v8::String>, v8::Local<v8::Value>, const SetterCallbackInfo&)’:
../src/fibers.cc:741:43: error: no matching function for call to ‘v8::Value::ToNumber()’
    Coroutine::pool_size = value->ToNumber()->Value();
                                           ^
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:2666:44: note: candidate: v8::MaybeLocal<v8::Number> v8::Value::ToNumber(v8::Local<v8::Context>) const
   V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
                                            ^~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:2666:44: note:   candidate expects 1 argument, 0 provided
In file included from /root/.cache/node-gyp/12.18.2/include/node/v8-internal.h:14:0,
                 from /root/.cache/node-gyp/12.18.2/include/node/v8.h:27,
                 from /root/.cache/node-gyp/12.18.2/include/node/node.h:67,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:2682:31: note: candidate: v8::Local<v8::Number> v8::Value::ToNumber(v8::Isolate*) const
                 Local<Number> ToNumber(Isolate* isolate) const);
                               ^
/root/.cache/node-gyp/12.18.2/include/node/v8config.h:328:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
/root/.cache/node-gyp/12.18.2/include/node/v8.h:2682:31: note:   candidate expects 1 argument, 0 provided
                 Local<Number> ToNumber(Isolate* isolate) const);
                               ^
/root/.cache/node-gyp/12.18.2/include/node/v8config.h:328:3: note: in definition of macro ‘V8_DEPRECATED’
   declarator __attribute__((deprecated(message)))
   ^~~~~~~~~~
../src/fibers.cc: In static member function ‘static uni::FunctionType Fiber::GetFibersCreated(v8::Local<v8::String>, const GetterCallbackInfo&)’:
../src/fibers.cc:748:23: error: ‘NewNumber’ is not a member of ‘uni’
    return uni::Return(uni::NewNumber(Isolate::GetCurrent(), Coroutine::coroutines_created()), info);
                       ^~~
../src/fibers.cc:748:99: error: return-statement with a value, in function returning 'void' [-fpermissive]
    return uni::Return(uni::NewNumber(Isolate::GetCurrent(), Coroutine::coroutines_created()), info);
                                                                                                   ^
../src/fibers.cc: In static member function ‘static void Fiber::Init(int)’:
../src/fibers.cc:766:4: error: ‘Handle’ was not declared in this scope
    Handle<FunctionTemplate> tmpl = uni::NewFunctionTemplate(isolate, New);
    ^~~~~~
../src/fibers.cc:766:27: error: expected primary-expression before ‘>’ token
    Handle<FunctionTemplate> tmpl = uni::NewFunctionTemplate(isolate, New);
                           ^
../src/fibers.cc:766:36: error: ‘NewFunctionTemplate’ is not a member of ‘uni’
    Handle<FunctionTemplate> tmpl = uni::NewFunctionTemplate(isolate, New);
                                    ^~~
../src/fibers.cc:767:41: error: no matching function for call to ‘Reset(v8::Isolate*&, v8::Persistent<v8::FunctionTemplate>&, v8::Persistent<v8::FunctionTemplate>&)’
    uni::Reset(isolate, Fiber::tmpl, tmpl);
                                         ^
../src/fibers.cc:70:7: note: candidate: template<class T> void uni::Reset(v8::Isolate*, v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, int)
  void Reset(Isolate* isolate, Persistent<T>& persistent, Handle<T> handle) {
       ^~~~~
../src/fibers.cc:70:7: note:   template argument deduction/substitution failed:
../src/fibers.cc:767:41: note:   cannot convert ‘Fiber::tmpl’ (type ‘v8::Persistent<v8::FunctionTemplate>’) to type ‘int’
    uni::Reset(isolate, Fiber::tmpl, tmpl);
                                         ^
../src/fibers.cc:768:8: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::FunctionTemplate>’
    tmpl->SetClassName(uni::NewLatin1Symbol(isolate, "Fiber"));
        ^~
../src/fibers.cc:768:23: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    tmpl->SetClassName(uni::NewLatin1Symbol(isolate, "Fiber"));
                       ^~~
../src/fibers.cc:772:20: error: expected primary-expression before ‘>’ token
    Handle<Signature> sig = uni::NewSignature(isolate, tmpl);
                    ^
../src/fibers.cc:772:22: error: ‘sig’ was not declared in this scope
    Handle<Signature> sig = uni::NewSignature(isolate, tmpl);
                      ^~~
../src/fibers.cc:772:28: error: ‘NewSignature’ is not a member of ‘uni’
    Handle<Signature> sig = uni::NewSignature(isolate, tmpl);
                            ^~~
../src/fibers.cc:773:8: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::FunctionTemplate>’
    tmpl->InstanceTemplate()->SetInternalFieldCount(1);
        ^~
../src/fibers.cc:776:25: error: expected primary-expression before ‘>’ token
    Handle<ObjectTemplate> proto = tmpl->PrototypeTemplate();
                         ^
../src/fibers.cc:776:27: error: ‘proto’ was not declared in this scope
    Handle<ObjectTemplate> proto = tmpl->PrototypeTemplate();
                           ^~~~~
../src/fibers.cc:776:39: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::FunctionTemplate>’
    Handle<ObjectTemplate> proto = tmpl->PrototypeTemplate();
                                       ^~
../src/fibers.cc:777:15: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    proto->Set(uni::NewLatin1Symbol(isolate, "reset"),
               ^~~
../src/fibers.cc:778:5: error: ‘NewFunctionTemplate’ is not a member of ‘uni’
     uni::NewFunctionTemplate(isolate, Reset, Handle<Value>(), sig));
     ^~~
../src/fibers.cc:778:58: error: expected primary-expression before ‘>’ token
     uni::NewFunctionTemplate(isolate, Reset, Handle<Value>(), sig));
                                                          ^
../src/fibers.cc:778:60: error: expected primary-expression before ‘)’ token
     uni::NewFunctionTemplate(isolate, Reset, Handle<Value>(), sig));
                                                            ^
../src/fibers.cc:779:15: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    proto->Set(uni::NewLatin1Symbol(isolate, "run"),
               ^~~
../src/fibers.cc:780:5: error: ‘NewFunctionTemplate’ is not a member of ‘uni’
     uni::NewFunctionTemplate(isolate, Run, Handle<Value>(), sig));
     ^~~
../src/fibers.cc:780:56: error: expected primary-expression before ‘>’ token
     uni::NewFunctionTemplate(isolate, Run, Handle<Value>(), sig));
                                                        ^
../src/fibers.cc:780:58: error: expected primary-expression before ‘)’ token
     uni::NewFunctionTemplate(isolate, Run, Handle<Value>(), sig));
                                                          ^
../src/fibers.cc:781:15: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    proto->Set(uni::NewLatin1Symbol(isolate, "throwInto"),
               ^~~
../src/fibers.cc:782:5: error: ‘NewFunctionTemplate’ is not a member of ‘uni’
     uni::NewFunctionTemplate(isolate, ThrowInto, Handle<Value>(), sig));
     ^~~
../src/fibers.cc:782:62: error: expected primary-expression before ‘>’ token
     uni::NewFunctionTemplate(isolate, ThrowInto, Handle<Value>(), sig));
                                                              ^
../src/fibers.cc:782:64: error: expected primary-expression before ‘)’ token
     uni::NewFunctionTemplate(isolate, ThrowInto, Handle<Value>(), sig));
                                                                ^
../src/fibers.cc:783:23: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    proto->SetAccessor(uni::NewLatin1Symbol(isolate, "started"), GetStarted);
                       ^~~
../src/fibers.cc:786:19: error: expected primary-expression before ‘>’ token
    Handle<Function> yield = uni::NewFunctionTemplate(isolate, Yield_)->GetFunction();
                   ^
../src/fibers.cc:786:21: error: ‘yield’ was not declared in this scope
    Handle<Function> yield = uni::NewFunctionTemplate(isolate, Yield_)->GetFunction();
                     ^~~~~
../src/fibers.cc:786:29: error: ‘NewFunctionTemplate’ is not a member of ‘uni’
    Handle<Function> yield = uni::NewFunctionTemplate(isolate, Yield_)->GetFunction();
                             ^~~
../src/fibers.cc:787:17: error: expected primary-expression before ‘>’ token
    Handle<String> sym_yield = uni::NewLatin1Symbol(isolate, "yield");
                 ^
../src/fibers.cc:787:19: error: ‘sym_yield’ was not declared in this scope
    Handle<String> sym_yield = uni::NewLatin1Symbol(isolate, "yield");
                   ^~~~~~~~~
../src/fibers.cc:787:31: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    Handle<String> sym_yield = uni::NewLatin1Symbol(isolate, "yield");
                               ^~~
../src/fibers.cc:788:4: error: ‘target’ was not declared in this scope
    target->Set(sym_yield, yield);
    ^~~~~~
../src/fibers.cc:791:19: error: expected primary-expression before ‘>’ token
    Handle<Function> fn = tmpl->GetFunction();
                   ^
../src/fibers.cc:791:21: error: ‘fn’ was not declared in this scope
    Handle<Function> fn = tmpl->GetFunction();
                     ^~
../src/fibers.cc:791:30: error: base operand of ‘->’ has non-pointer type ‘v8::Persistent<v8::FunctionTemplate>’
    Handle<Function> fn = tmpl->GetFunction();
                              ^~
../src/fibers.cc:793:20: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    fn->SetAccessor(uni::NewLatin1Symbol(isolate, "current"), GetCurrent);
                    ^~~
../src/fibers.cc:794:20: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    fn->SetAccessor(uni::NewLatin1Symbol(isolate, "poolSize"), GetPoolSize, SetPoolSize);
                    ^~~
../src/fibers.cc:795:20: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    fn->SetAccessor(uni::NewLatin1Symbol(isolate, "fibersCreated"), GetFibersCreated);
                    ^~~
../src/fibers.cc:798:16: error: ‘NewLatin1Symbol’ is not a member of ‘uni’
    target->Set(uni::NewLatin1Symbol(isolate, "Fiber"), fn);
                ^~~
../src/fibers.cc: At global scope:
../src/fibers.cc:814:11: error: variable or field ‘init’ declared void
 void init(Handle<Object> target) {
           ^~~~~~
../src/fibers.cc:814:11: error: ‘Handle’ was not declared in this scope
../src/fibers.cc:814:24: error: expected primary-expression before ‘>’ token
 void init(Handle<Object> target) {
                        ^
../src/fibers.cc:814:26: error: ‘target’ was not declared in this scope
 void init(Handle<Object> target) {
                          ^~~~~~
../src/fibers.cc: In instantiation of ‘void uni::Return(v8::Persistent<T, v8::NonCopyablePersistentTraits<T> >&, uni::GetterCallbackInfo) [with T = v8::Object; uni::GetterCallbackInfo = v8::PropertyCallbackInfo<v8::Value>]’:
../src/fibers.cc:727:45:   required from here
../src/fibers.cc:106:3: warning: ‘void v8::ReturnValue<T>::Set(const v8::Persistent<S>&) [with S = v8::Object; T = v8::Value]’ is deprecated: Use Global<> instead [-Wdeprecated-declarations]
   info.GetReturnValue().Set(handle);
   ^~~~
In file included from /root/.cache/node-gyp/12.18.2/include/node/node.h:67:0,
                 from ../src/coroutine.h:1,
                 from ../src/fibers.cc:1:
/root/.cache/node-gyp/12.18.2/include/node/v8.h:10424:6: note: declared here
 void ReturnValue<T>::Set(const Persistent<S>& handle) {
      ^~~~~~~~~~~~~~
fibers.target.mk:118: recipe for target 'Release/obj.target/fibers/src/fibers.o' failed
make: *** [Release/obj.target/fibers/src/fibers.o] Error 1
make: Leaving directory '/var/www/asterisk-agi-server/node_modules/fibers/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 4.9.0
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--release"
gyp ERR! cwd /var/www/asterisk-agi-server/node_modules/fibers
gyp ERR! node -v v12.18.2
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
node-gyp exited with code: 1
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
Alpine users please run: `sudo apk add python make g++`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node build.js || nodejs build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-07-20T07_52_04_883Z-debug.log

Mapper multiple scripts

it possible to map multiple scripts?

I tried this but it did not work:

function hello(channel) {
	console.log("hello")
  	console.log('Script got call %s -> %s', channel.request.callerid, channel.request.extension);
}

function bye(channel) {
        console.log("bye")
  	console.log('Script got call %s -> %s', channel.request.callerid, channel.request.extension);
}

/* 
	Start server 
*/
var server = new AGIServer({
    helloScript: hello,
    byeScript: bye
}, 4573);

exten => s,1,Agi(agi://localhost/helloScript)
exten => s,n,Agi(agi://localhost/byeScript)

Error:

events.js:165
      throw err;
      ^

Error: Uncaught, unspecified "error" event. (Could not find requested script)
    at AGIChannel.emit (events.js:163:17)
    at new AGIChannel (/opt/agi-server/node_modules/agi-node/lib/agi-channel.js:64:10)
    at AGIConnection.handleData (/opt/agi-server/node_modules/agi-node/lib/agi-server.js:46:21)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)

How to sync properly

Hi,

I have another question... I got the following script which executes a POST request and fetches an answer. I want to overwrite the var caller_response with the response from the request. Unfortunately, due to the asynchronous processing, the script finishes without waiting for response, so caller_response always is like initiated.

I've googled a lot and I'm sure that's the problem, but I can't figure it out! Can you help me?

function submitgs(channel) {
  try {
    console.log('Script got call %s -> %s', channel.request.callerid, channel.request.extension);
    channel.getVariable('TRANSCRIPT');
    console.log('Found Transcript: '+channel.getVariable('TRANSCRIPT'));
    var caller_response = "Einen\u00A0Moment\u00A0.Ich\u00A0verarbeite.";

      var headers = {
          'User-Agent':       'Super Agent/0.0.1',
          'Content-Type':     'application/x-www-form-urlencoded'
      };

      // Configure the request
      var options = {
          url: 'http://.../v5/bot/processUserInput?client_id=1111&text='+channel.getVariable('TRANSCRIPT'),
          method: 'POST',
          headers: headers
      };
      `console.log('Request` from URL');
      // Start the request
      request(options, function (error, response, body) {
          if (!error && response.statusCode == 200) {
              // Print out the response body
              caller_response = body;
              //channel.streamFile(setResponseToTTS.sync(null, response));
              console.log(body)
          }
      });

    channel.setVariable('RESPONSE', caller_response);
    console.log('Response Found: '+channel.getVariable('RESPONSE')) ;

  } catch (ex) {
    console.log('Error in script', ex);
  }

}

add listener

Hello,
how can I add listener, for example onHangup?
When the call will be finished, I need to calculate it.

Can I do like this

function testScript(channel) {
channel.on("hangup", function(){
// do something....
});
}

Can I get arguments passed to mapped script ?

Hello.
Asterisk can call AGI with arguments:
AGI(command[,arg1[,arg2[,…]]])
If I call agi from dial plan like this:
exten => _X.,1,AGI(agi://localhost:3000/myscript, 1,2,3)
Can I get these 1,2,3 somewhere in my myscript ?
Thanks!

self.hander('hangup');

Hello,
I just simply used your example and what I can see after the caller hangs up:

/home/igor/work/899/node_modules/agi-node/lib/agi-server.js:31
self.hander('hangup');
^
TypeError: undefined is not a function
at AGIConnection.handleData (/home/igor/work/899/node_modules/agi-node/lib/agi-server.js:31:12)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:529:20)

TypeError: Cannot read property 'destroy' of null

If i put 'channel' to a function, an error occurred.

function testScript(channel) {
console.log('Script got call %s -> %s', channel.request.callerid, channel.request.extension);
var test = function() {
channel.exec("Dial", "PJSIP/6999,10");
console.log('res', res);
};
test();
}

image

Cannot read property 'write' of null

Hi.

I'm getting this error when I try to use the getVariable() function on channel.

TypeError: Cannot read property 'write' of null at AGIChannel.<anonymous> (/Users/mario.lenis/Dev/4sales-agi/node_modules/agi-node/lib/agi-server.js:51:18) at emitTwo (events.js:125:13) at AGIChannel.emit (events.js:213:7) at AGIChannel._sendRequest (/Users/mario.lenis/Dev/4sales-agi/node_modules/agi-node/lib/agi-channel.js:96:8) at Function.future (/Users/mario.lenis/Dev/4sales-agi/node_modules/syncho/lib/syncho.js:25:8) at Function.sync (/Users/mario.lenis/Dev/4sales-agi/node_modules/syncho/lib/syncho.js:14:24) at AGIChannel.sendRequest (/Users/mario.lenis/Dev/4sales-agi/node_modules/agi-node/lib/agi-channel.js:100:28) at AGIChannel.getVariable (/Users/mario.lenis/Dev/4sales-agi/node_modules/agi-node/lib/agi-channel.js:158:21)

Problem seems to be here.
Line 51 on agi-server.js
channel.on('request', function(req) {
self.conn.write(req + '\n');
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.