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

Basic server code isn't running #55

Open
adil-mafzool opened this issue Apr 16, 2021 · 3 comments
Open

Basic server code isn't running #55

adil-mafzool opened this issue Apr 16, 2021 · 3 comments

Comments

@adil-mafzool
Copy link

adil-mafzool commented Apr 16, 2021

Trying the following basic server code to answer a call and bridge to a new call. But cannot seem to work?

call_handler = require('seem') =>
  caller = @data['Channel-Caller-ID-Number']
  callee = @data['Channel-Destination-Number']
  new_caller = yield db.getAsync "new_caller_for_#{caller}"
  yield @command 'answer'
  yield @command 'play-file', 'voicemail/vm-hello'
  yield @command 'set', "effective_caller_id_number=#{new_caller}"
  yield @command 'bridge', "sofia/egress/#{callee}@example.net"

require('esl').server(call_handler).listen(7000)

I am newbie to nodejs so not sure how to build a simple server to bridge an incoming call by making an out going call?
Do you have an example code for such basic server use-case?

@shimaore
Copy link
Owner

A side note: with recent Node.js and esl you would be better off using the async/await pattern rather than seem and yield (even though they do the same thing essentially). I'll grant you that the documentation needs some update :)

If you are using the server-mode of ESL (as in this example) you need to have FreeSwitch send calls to your Node.js application on port 7000.

The most efficient way to do this is to use

<param name="dialplan" value="inline:'socket:127.0.0.1:7000 async full'"/>

in your SIP profile's settings. (This will bypass the FreeSwitch dialplan.) This is my preferred method.

Another way is to use the FreeSwitch dialplan and insert something along the lines of

<condition field="destination_number" expression=".">
  <action application="socket" data="127.0.0.1:7000 async full"/>
</condition>

@adil-mafzool
Copy link
Author

@shimaore thanks for the reply! I know the FreeSwitch part but have issues with the above nodejs example where it doesn't work. Do you have simple server code I can try to bridge an incoming call by making an outgoing call?

@shimaore
Copy link
Owner

If I take the code you were referring to, an up-to-date implementation would look like this:

const call_handler = async () => {
  const caller = this.data['Channel-Caller-ID-Number']
  const callee = this.data['Channel-Destination-Number']
  const new_caller = await db.getAsync(`new_caller_for_${caller}`)
  await this.command('answer')
  await this.command('play-file', 'voicemail/vm-hello')
  await this.command('set', `effective_caller_id_number=${new_caller}`)
  await this.command('bridge', `sofia/egress/${callee}@example.net`)
};
require('esl').server(call_handler).listen(7000)

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