Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ekim
Ekim

Posted on

     

Asterisk Manager with JavaScript

Weekly sharing

Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer.

Previously

Brief intro of Asterisk Manager

Introduction

This time, we will go through how we could control the asterisk through our codes. Below, I will use JavaScript to illustrate how you could fiddle with asterisk without the CLI (command-line interface). And as the previous sharing, my pjsip.conf and extensions.conf align withmy first sharing.

Set up your environment

  • Install the package we need
npminstallasterisk-ami-client
Enter fullscreen modeExit fullscreen mode

Coding section

  • Create amain.jsfile and copy these
constAmiClient=require("asterisk-ami-client");letclient=newAmiClient();client.connect("<YOUR USERNAME>","<YOUR PASSWORD>",{host:"127.0.0.1",port:5038})// connect to your AMI remotely.then(()=>{client.on('connect',()=>console.log('connect'))// show connection logs in terminal.on('event',event=>console.log(event))// show AMI event logs in terminal.on('response',response=>console.log(response))// show response logs in terminal.on('disconnect',()=>console.log('disconnect'))// show disconnection logs in terminal.on('reconnection',()=>console.log('reconnection'))// show reconnection logs in terminal.on('internalError',error=>console.log(error))// show AMI error logs in terminal.action({// manager actionAction:"Originate",// Originate callChannel:"PJSIP/7000",// calling from endpoint 7000Exten:"7100",// expected to be received by endpoint 7100Context:"interaction",Priority:"1",})}).catch(error=>console.log(error));
Enter fullscreen modeExit fullscreen mode
  • please replace"<YOUR USERNAME>" and"<YOUR PASSWORD>" with your AMI login username and password.

  • Then, it's time to run the code

    node main.js# make sure you execute the command in the correct path that has the newly created main.js
Enter fullscreen modeExit fullscreen mode
  • You should now be able to originate a call without using the CLI. And in your terminal, your could see all the states and processes of asterisk when you connect to the AMI and originate the call. You could use them to do different kinds of things.

  • For example, think about converting voice messages in the voicemail into texts, and then send those texts to a telegram group. Wouldn't it be amazing?

Conclusion

  • It is a short and simple sharing, but you could do various things based on it. I tend to keep things easy and avoid people getting overwhelmed by the asterisk thing. I hope you enjoy my reading so far. In the meantime, stay healthy and stay tuned for more content !!!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromEkim

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp