### Install wscat via npm Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI Installs the wscat command-line utility, which is used to establish a WebSocket connection for receiving ARI events. Requires Node.js and npm to be installed. ```bash apt-get install npm npm install -g wscat ``` -------------------------------- ### AEAP Setup Response - Example 1 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of a 'setup' response confirming the 'ulaw' codec selection. ```json { "response": "setup", "id": "7180e464-c022-40e6-a49c-9d2007f008a7", "codecs": [{ "name": "ulaw" }], } ``` -------------------------------- ### AEAP Setup Request - Example 3 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of an AEAP 'setup' request including optional 'params' for language and gender. ```json { "request": "setup", "id": "b3eda99f-464f-477e-b8a3-4ebafda0b482", "version": "0.1.0", "codecs": [ { "name": "ulaw" } ], "params": { "language": "en", "gender": "male" }, } ``` -------------------------------- ### Install MySQL Server and Start Service (Bash) Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/ODBC/Getting-Asterisk-Connected-to-MySQL-via-ODBC Installs the MySQL server package using yum and starts the mysqld service. This is the initial step for setting up MySQL. ```bash # sudo yum install mysql-server # sudo service mysqld start ``` -------------------------------- ### Install Blink SIP Client using setup.py Source: https://docs.asterisk.org/Deployment/Secure-Calling/Secure-Calling-Tutorial/Installing-Blink-SIP-client Installs the Blink SIP client after downloading and extracting its source code. This process involves navigating to the source directory and executing the Python setup script. ```bash sudo python setup.py install ``` -------------------------------- ### AEAP Setup Request - Example 1 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of a basic AEAP 'setup' request specifying the 'ulaw' codec. ```json { "request": "setup", "id": "9c8d7625-d70d-4225-8b4f-53063ea8e774", "version": "0.1.0", "codecs": [ { "name": "ulaw" } ], } ``` -------------------------------- ### Install Asterisk Sample Configurations Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 This command installs the sample configuration files for Asterisk. It's important to back up any existing custom configurations in `/etc/asterisk` before running this command, as it will overwrite them. ```bash sudo make samples ``` -------------------------------- ### PJSIP Configuration Wizard Examples Source: https://docs.asterisk.org/Asterisk_22_Documentation/API_Documentation/Module_Configuration/res_pjsip_config_wizard Examples demonstrating how to use the PJSIP configuration wizard for phone provisioning and trunk setup. ```APIDOC ## PJSIP Configuration Wizard Examples ### Phone Configuration Example (`myphone`) This configuration snippet creates the necessary endpoint, aor, contact, auth, and phoneprov objects for a phone to receive provisioning information, register, and handle calls. ```ini [myphone] type = wizard sends_auth = no accepts_auth = yes sends_registrations = no accepts_registrations = yes has_phoneprov = yes transport = ipv4 has_hint = yes hint_exten = 1000 inbound_auth/username = testname inbound_auth/password = test password endpoint/allow = ulaw endpoint/context = default phoneprov/MAC = 001122aa4455 phoneprov/PROFILE = profile1 ``` ### Trunk Configuration Example (`mytrunk`) This configuration snippet creates the necessary endpoint, aor, contact, auth, identify, and registration objects for a trunk to another PBX or ITSP that requires registration. ```ini [mytrunk] type = wizard sends_auth = yes accepts_auth = no sends_registrations = yes accepts_registrations = no transport = ipv4 remote_hosts = sip1.myitsp.com:5060,sip2.myitsp.com:5060 outbound_auth/username = testname outbound_auth/password = test password endpoint/allow = ulaw endpoint/context = default ``` ``` -------------------------------- ### Install Asterisk Initialization Script (Bash) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Installing-Initialization-Scripts Installs the Asterisk initscript, which is responsible for starting, monitoring, stopping, and restarting the Asterisk process automatically when the server boots. This command is executed from the Asterisk source directory. ```bash #!/bin/bash # Install the Asterisk init script make config ``` -------------------------------- ### Install ASTTest using Make Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 This snippet shows the standard command-line steps to compile and install the ASTTest tool using the 'make' utility. It assumes the user has navigated to the 'asttest' directory. ```bash cd asttest make sudo make install ``` -------------------------------- ### Install sipp Tool Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 This command installs the compiled sipp tool to the system. It requires superuser privileges. ```bash sudo make install ``` -------------------------------- ### Build and Install sipp Tool Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 This snippet demonstrates how to download, build, and install the sipp tool from its source code. It includes steps for checking out a specific known-working version and configuring the build with necessary options like OpenSSL, PCAP, RTPStream, SCTP, and GSL. Ensure you have the required development packages installed before running this. ```bash cd /usr/src/asterisk git clone https://github.com/SIPp/sipp.git cd sipp git checkout v3.6.0 ## This is the latest version we KNOW works. ./build.sh --prefix=/usr --with-openssl --with-pcap --with-rtpstream --with-sctp --with-gsl CFLAGS=-w ``` -------------------------------- ### AEAP Setup Request - Example 2 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of an AEAP 'setup' request with multiple codecs, including 'opus' with an attribute. ```json { "request": "setup", "id": "7180e464-c022-40e6-a49c-9d2007f008a7", "version": "0.1.0", "codecs": [ { "name": "ulaw" }, { "name": "opus", "attributes": { "maxplaybackrate": 8000 } } ], } ``` -------------------------------- ### Install curl via apt-get Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI Installs the curl utility, which is used to send HTTP requests to control channels within the Stasis dialplan application via ARI. This is a common method for interacting with RESTful APIs. ```bash apt-get install curl ``` -------------------------------- ### Start Tigase Server Source: https://docs.asterisk.org/Configuration/Interfaces/Distributed-Device-State/Distributed-Device-State-with-XMPP-PubSub This command starts the Tigase server using its startup script. It requires navigating to the Tigase installation directory and specifying the path to the configuration file. ```bash # cd /opt/Tigase-4.3.1-b1858 # ./scripts/tigase.sh start etc/tigase.conf ``` -------------------------------- ### Asterisk Error Response Example: Setup Failed Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of an error response for a 'setup' request, indicating a failure due to unsupported codecs. It includes the request type, ID, and a specific error message. ```json { "response": "setup", "id": "b3eda99f-464f-477e-b8a3-4ebafda0b482", "error_msg": "No supported codec(s)" } ``` -------------------------------- ### Install Asterisk Sample Configuration Files Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Installing-Sample-Files This command installs a set of sample configuration files for Asterisk. Existing modified sample files will be renamed with a .old extension before installation. ```bash [root@server asterisk-14.X.Y]# make samples ``` -------------------------------- ### Start DAHDI Service (Bash) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Validating-Your-Installation These commands demonstrate how to start the DAHDI service. The primary command uses the initscript. Alternative commands for Red Hat-based systems (`service`) and Debian-based systems (`invoke-rc.d`) are also provided. ```bash [root@server asterisk-14.X.Y]# /etc/init.d/dadhi start ``` ```bash [root@server asterisk-14.X.Y]# service dahdi start ``` ```bash [root@server asterisk-14.X.Y]# invoke-rc.d dahdi start ``` -------------------------------- ### Install Asterisk Log Rotation Script (Bash) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Installing-Initialization-Scripts Installs the logrotation script for Asterisk. This script helps manage log files by compressing and rotating them, saving disk space and improving searchability. Execute this command from the Asterisk source directory. ```bash #!/bin/bash # Install the Asterisk log rotation script make install-logrotate ``` -------------------------------- ### Configure ARI User in Asterisk Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI Sets up an ARI user with credentials in ari.conf. 'enabled = yes' and 'pretty = yes' enable the ARI interface and pretty-print JSON responses. The 'asterisk' user is for demonstration; use secure credentials in production. ```ini [general] enabled = yes pretty = yes [asterisk] type = user read_only = no password = asterisk ``` -------------------------------- ### Check sipp Tool Version Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 After building and installing sipp, this command verifies the installed version to ensure it meets the required specification. A successful output indicates the tool is ready for use. ```bash ./sipp -v ``` -------------------------------- ### Connecting to Asterisk ARI Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI This section details how to establish a WebSocket connection to Asterisk ARI using wscat and subscribe to events for a specific application. ```APIDOC ## Connect to Asterisk using `wscat` ### Description Establish a WebSocket connection to the Asterisk ARI interface to receive real-time events. ### Method GET (via WebSocket) ### Endpoint `ws://localhost:8088/ari/events?api_key=&app=` ### Parameters #### Query Parameters - **api_key** (string) - Required - The API key for authentication (e.g., `asterisk:asterisk`). - **app** (string) - Required - The name of the Stasis application to subscribe to (e.g., `hello-world`). ### Request Example ```bash wscat -c "ws://localhost:8088/ari/events?api_key=asterisk:asterisk&app=hello-world" ``` ### Response Upon connection, Asterisk will confirm the WebSocket connection and the creation of the specified Stasis application. #### Success Response (Connection Established) ``` connected (press CTRL+C to quit) Creating Stasis app 'hello-world' ``` #### Event Example (StasisStart) ```json { "application":"hello-world", "type":"StasisStart", "timestamp":"2014-05-20T13:15:27.131-0500", "args":[], "channel":{ "id":"1400609726.3", "state":"Up", "name":"PJSIP/1000-00000001", "caller":{ "name":"", "number":""}, "connected":{ "name":"", "number":""}, "accountcode":"", "dialplan":{ "context":"default", "exten":"1000", "priority":3}, "creationtime":"2014-05-20T13:15:26.628-0500"} } ``` ``` -------------------------------- ### Build and Install Asterisk with Development Flags Source: https://docs.asterisk.org/Test-Suite-Documentation/Using-Python3 This section covers building and installing Asterisk with specific development flags enabled. The `--enable-dev-mode` flag is crucial for testing, and `--disable-binary-modules` simplifies the build process by excluding external codecs. The `make install-headers` command is necessary for the testsuite. ```bash make sudo make install sudo make install-headers ``` -------------------------------- ### Asterisk SLA Configuration (sla.conf) Source: https://docs.asterisk.org/Configuration/Applications/Shared-Line-Appearances-SLA/SLA-Configuration-Examples/Basic-SLA-Configuration-Example This snippet shows the basic configuration for SLA in Asterisk's sla.conf file. It defines trunks (line1, line2) and stations (station1, station2, station3) with their respective device and context mappings. Dependencies include dahdi.conf and sip.conf for device and context setup. ```asterisk [line1] type=trunk device=DAHDI/1 autocontext=line1 [line2] type=trunk device=DAHDI/2 autocontext=line2 [station] type=station trunk=line1 trunk=line2 autocontext=sla_stations [station1](station) device=SIP/station1 [station2](station) device=SIP/station2 [station3](station) device=SIP/station3 ``` -------------------------------- ### Start Asterisk Service (Bash) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Validating-Your-Installation This command initiates the Asterisk service using its initscript. Asterisk typically runs as a background daemon, so no output is usually displayed on the command line upon successful startup. ```bash [root@server asterisk-14.X.Y]# /etc/init.d/asterisk start Starting asterisk: ``` -------------------------------- ### Install Sample Configuration Files Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Building-and-Installing-Asterisk Installs the sample configuration files to the default Asterisk configuration directory (`/etc/asterisk/`). This command will overwrite any existing configuration files. ```bash make samples ``` -------------------------------- ### Download Asterisk using wget Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/What-to-Download This snippet demonstrates how to download the Asterisk source code using the `wget` command-line utility. It retrieves a specific version (asterisk-14-current.tar.gz) from the official Asterisk download server. The output shows the download progress and confirmation. ```bash [root@server:/usr/local/src]# wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-14-current.tar.gz --2017-04-28 15:45:36-- https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-14-current.tar.gz Resolving downloads.asterisk.org (downloads.asterisk.org)... 76.164.171.238 Connecting to downloads.asterisk.org (downloads.asterisk.org)|76.164.171.238|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 40692588 (39M) [application/x-gzip] Saving to: ‘asterisk-14-current.tar.gz’ asterisk-14-current.tar.gz 100%[======================================================================>] 38.81M 3.32MB/s in 12s 2017-04-28 15:45:47 (3.37 MB/s) - ‘asterisk-14-current.tar.gz’ saved [40692588/40692588] ``` -------------------------------- ### Generate Development Documentation Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Building-and-Installing-Asterisk Uses doxygen to locally generate HTML development documentation from the Asterisk source code. The documentation is created in the `doc/` subdirectory of the source code. ```bash make progdocs ``` -------------------------------- ### Setting Up Documentation Build Environment Source: https://docs.asterisk.org/Contributing-to-the-Documentation These commands outline the steps to set up a Python virtual environment and install dependencies required for building the Asterisk documentation locally. It includes installing virtualenv, creating the environment, activating it, and installing packages from requirements.txt. ```bash # Install python3-virtualenv $ sudo (apt | dnf | yum) install python3-virtualenv $ cd asterisk-documentation $ python3 -m venv --system-site-packages --symlinks .venv $ source .venv/bin/activate $ pip install -r requirements.txt ``` -------------------------------- ### AEAP Get Request - Example 1 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of a 'get' request to retrieve the 'language' parameter. ```json { "request": "get", "id": "f066e049-d4ef-4093-a05b-0effef1bc077", "params": ["language"], } ``` -------------------------------- ### AEAP Get Response - Example 1 Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of a 'get' response returning the 'language' parameter with its value. ```json { "response": "get", "id": "f066e049-d4ef-4093-a05b-0effef1bc077", "params": { "language" : "en" }, } ``` -------------------------------- ### Install Asterisk to a Custom Directory Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Building-and-Installing-Asterisk Configures the Asterisk installation to use a custom directory specified by the --prefix option. This allows for sandboxing Asterisk instances or installing to non-default locations. ```bash [root@server asterisk-14.X.Y]# ./configure --prefix=/usr/local/my_special_folder ``` -------------------------------- ### Asterisk Endpoint Configuration Source: https://docs.asterisk.org/Development/Roadmap/Asterisk-12-Projects/New-SIP-channel-driver/New-SIP-Channel-Driver-Architecture/res_sip-design/Roadmap/Asterisk-12-Projects/New-SIP-channel-driver/New-SIP-Channel-Driver-Architecture/res_sip-design/Endpoints-and-Location-A-Match-Made-in-Heaven Example configuration for an Asterisk endpoint. This sets up basic parameters like context, disallowed codecs, allowed codecs, and associated AORs. ```asterisk [5000] type=endpoint context=default disallow=all allow=g722 allow=ulaw aors=5000 ``` -------------------------------- ### Asterisk Error Response Example: Get Failed Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP An example of an error response for a 'get' request, indicating that a requested parameter (language) is not available. It shows the response type, ID, and the error message. ```json { "response": "get", "id": "f066e049-d4ef-4093-a05b-0effef1bc077", "error_msg": "No language parameter available" } ``` -------------------------------- ### Verify Asterisk Corosync Cluster Members (CLI) Source: https://docs.asterisk.org/Configuration/Interfaces/Distributed-Device-State/Corosync These snippets show the expected output from the Asterisk CLI command 'corosync show members' to verify the cluster status. The first example shows a single node setup, while the second shows a two-node cluster. This command is used after installing and configuring Corosync and Asterisk. ```bash *CLI> corosync show members ============================================================= === Cluster members ========================================= ============================================================= === === Node 1 === --> Group: asterisk === --> Address 1: === ============================================================= ``` ```bash *CLI> corosync show members ============================================================= === Cluster members ========================================= ============================================================= === === Node 1 === --> Group: asterisk === --> Address 1: === Node 2 === --> Group: asterisk === --> Address 1: === ============================================================= ``` -------------------------------- ### Asterisk Dialing Examples Source: https://docs.asterisk.org/Development/Roadmap/Asterisk-12-Projects/New-SIP-channel-driver/New-SIP-Channel-Driver-Architecture/res_sip-design/Roadmap/Asterisk-12-Projects/New-SIP-channel-driver/New-SIP-Channel-Driver-Architecture/res_sip-design/Endpoints-and-Location-A-Match-Made-in-Heaven Examples demonstrating how to dial using the Dial application in Asterisk, covering endpoints, explicit AORs, and explicit SIP URIs. ```asterisk Dial(PJSIP/5000) ``` ```asterisk Dial(PJSIP/5000/5000) ``` ```asterisk Dial(PJSIP/5000/sip:1234@test.com) ``` -------------------------------- ### Build and Install pjproject Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Prerequisites/PJSIP-pjproject Commands to build and install the pjproject library after configuration. It first ensures dependencies are met, then compiles the source code, and finally installs the compiled libraries and headers. ```bash # make dep # make # make install ``` -------------------------------- ### Asterisk Static Realtime HTTP GET Request Example Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/cURL This snippet demonstrates an example HTTP GET request made by Asterisk to retrieve static realtime data. It specifies the target file ('pjsip.conf') as a URL parameter. The request includes standard HTTP headers like 'User-Agent' and 'Host'. ```http GET /astconfig/static?file=pjsip.conf HTTP/1.1 User-Agent: asterisk-libcurl-agent/1.0 Host: localhost:8000 Accept */* ``` -------------------------------- ### Install Asterisk Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Building-and-Installing-Asterisk Installs the compiled Asterisk program and modules to the system. This command should be run after a successful compilation. ```bash [root@server asterisk-14.X.Y]# make install ``` -------------------------------- ### Secure MySQL Installation (Bash) Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/ODBC/Getting-Asterisk-Connected-to-MySQL-via-ODBC Executes the mysql_secure_installation script to apply basic security measures to the MySQL installation. Recommended for production environments. ```bash # sudo /usr/bin/mysql_secure_installation ``` -------------------------------- ### Configure and Build Asterisk Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Prerequisites/PJSIP-pjproject Standard commands to configure, build, and install Asterisk. Assumes Asterisk 15+ is being used. This process typically involves downloading and linking the pjproject dependency. ```bash ./configure make && make install ``` -------------------------------- ### Asterisk Dialplan Goto() Examples with Priority Labels Source: https://docs.asterisk.org/Deployment/Basic-PBX-Functionality/Auto-attendant-and-IVR-Menus/Goto-Application-and-Priority-Labels Demonstrates the usage of the Asterisk Goto() application with different parameter counts (1, 2, and 3) and the use of named priority labels (e.g., 'monkeys', 'start'). This allows for flexible navigation within and between dialplan contexts. Assumes Asterisk dialplan syntax. ```asterisk [StartingContext] exten => 100,1,Goto(monkeys) same => n,NoOp(We skip this) same => n(monkeys),Playback(tt-monkeys) same => n,Hangup() exten => 200,1,Goto(start,1) ; play tt-weasels then tt-monkeys exten => 300,1,Goto(start,monkeys) ; only play tt-monkeys exten => 400,1,Goto(JumpingContext,start,1) ; play hello-world exten => start,1,NoOp() same => n,Playback(tt-weasels) same => n(monkeys),Playback(tt-monkeys) [JumpingContext] exten => start,1,NoOp() same => n,Playback(hello-world) same => n,Hangup() ``` -------------------------------- ### Install Blink Dependencies on Ubuntu Source: https://docs.asterisk.org/Deployment/Secure-Calling/Secure-Calling-Tutorial/Installing-Blink-SIP-client Installs essential Python libraries required for the Blink SIP client on Ubuntu 12.04. This command ensures all prerequisites are met before proceeding with the Blink installation. ```bash sudo apt-get update sudo apt-get install python-sipsimple python-gnutls python-eventlib python-application python-cjson python-eventlet python-qt4 python-twisted-core python-zope.interface ``` -------------------------------- ### Start Asterisk in Console Mode with Verbosity 1 Source: https://docs.asterisk.org/Operation/Logging/Verbosity-in-Core-and-Remote-Consoles This command starts the Asterisk application in console mode, setting the root console verbosity to level 1. This is useful for initial setup or debugging. ```bash asterisk -cv ``` -------------------------------- ### Run Blink SIP Client Source: https://docs.asterisk.org/Deployment/Secure-Calling/Secure-Calling-Tutorial/Installing-Blink-SIP-client Executes the Blink SIP client from the command line. This command launches the application, which should then appear in the graphical desktop environment. ```bash blink ``` -------------------------------- ### Asterisk Message Router Setup and Callback Examples Source: https://docs.asterisk.org/Development/Roadmap/Asterisk-12-Projects/Asterisk-12-API-Improvements/Stasis-Message-Bus/Using-the-Stasis-Message-Bus This C code illustrates the setup and usage of the Asterisk stasis_message_router. It includes example callbacks for specific message types (e.g., stasis_cache_update_type) and a default route handler for miscellaneous messages, including the final unsubscribe message. The `load_module` function demonstrates router creation and addition of routes, while `unload_module` shows how to unsubscribe. ```c static void updates(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message) { /* Since this came from a message router, we know the type of the * message. We can cast the data without checking its type. */ struct stasis_cache_update *update = stasis_message_data(message); /* .. } static void default_route(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message) { if (stasis_subscription_final_message(sub, message)) { /* subscription cleanu */ } /* .. } static int load_module(void) { router = stasis_message_router_create( stasis_caching_get_topic(ast_channel_topic_all_cached())); if (!router) { return AST_MODULE_LOAD_FAILURE; } stasis_message_router_add(router, stasis_cache_update_type(), updates, NULL); stasis_message_router_set_default(router, default_route, NULL); /* .. return AST_MODULE_LOAD_SUCCESS; } static int unload_module(void) { /* .. */ stasis_message_router_unsubscribe(router); router = NULL; return 0; } ``` -------------------------------- ### Asterisk Dialplan: Replace Bytes at Offset (Byte Mode) Source: https://docs.asterisk.org/Asterisk_18_Documentation/API_Documentation/Dialplan_Functions/FILE Replaces a specified number of bytes in a file starting from a given offset. This example replaces 1 byte starting at offset 0 with 'bar'. ```asterisk same => n,Set(FILE(/tmp/test.txt,0,1)=bar) ``` -------------------------------- ### Build and Install Asterisk Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/cURL Compiles and installs Asterisk after modules have been selected, including the cURL related modules, onto the system. ```bash make && make install ``` -------------------------------- ### Asterisk Dialplan Hint Application Example Source: https://docs.asterisk.org/Asterisk_16_Documentation/API_Documentation/Module_Configuration/res_pjsip_config_wizard Demonstrates how to specify valid extensions.conf application expressions for dialplan hints. This includes examples of using Dial() and Gosub() with variables. ```asterisk-dialplan Dial(${HINT}) Gosub(stdexten,${EXTEN},1(${HINT})) ``` -------------------------------- ### List All Options in Menuselect Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Using-Menuselect-to-Select-Asterisk-Options Lists all available configuration options within the Asterisk Menuselect build system. This command is useful for understanding the full scope of customizable features before building Asterisk. ```bash [root@server asterisk-14.X.Y]# menuselect/menuselect --list-options ``` -------------------------------- ### Compile Asterisk Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Building-and-Installing-Asterisk Compiles the Asterisk source code. This is a prerequisite for installation and may take several minutes to complete. ```bash [root@server asterisk-14.X.Y]# make ``` -------------------------------- ### Asterisk Error: No SRTP Module Loaded Source: https://docs.asterisk.org/Deployment/Secure-Calling/Secure-Calling-Tutorial This error occurs when SRTP is enabled in the Asterisk configuration but the necessary SRTP module is not loaded. It indicates that the libsrtp library is either not installed or Asterisk was not recompiled after its installation. ```log [Jan 24 09:29:16] ERROR[10167]: chan_sip.c:27987 setup_srtp: No SRTP module loaded, can\'t setup SRTP session. ``` -------------------------------- ### Serving Asterisk Documentation Locally Source: https://docs.asterisk.org/Contributing-to-the-Documentation This command starts the built-in MkDocs web server to allow local viewing of the rendered documentation. The website is typically located in the './temp/site' directory. Options can be passed via SERVE_OPTS. ```bash $ make serve ``` -------------------------------- ### Install ODBC and MariaDB Connector (Bash) Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/ODBC/Getting-Asterisk-Connected-to-MySQL-via-ODBC Installs the necessary unixODBC packages and the MariaDB ODBC connector using yum. Development packages for unixODBC are included as they are needed for building Asterisk ODBC modules. ```bash # sudo yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel ``` ```bash # sudo yum install mariadb-connector-odbc ``` -------------------------------- ### Get Asterisk Build Machine Type (Dialplan) Source: https://docs.asterisk.org/Asterisk_16_Documentation/API_Documentation/Dialplan_Functions/VERSION This snippet shows how to get the machine type on which Asterisk was configured using VERSION(BUILD_MACHINE). The output is stored in the 'buildmachine' channel variable. This requires that build information is present in the Asterisk installation. ```asterisk-dialplan same => n,Set(buildmachine=${VERSION(BUILD_MACHINE)}) ``` -------------------------------- ### Combine Asterisk Debug and Verbose Levels on Startup Source: https://docs.asterisk.org/Operation/Logging/Basic-Logging-Start-up-Options Allows simultaneous configuration of both debug and verbose logging levels for Asterisk at startup. The combined arguments specify the desired intensity for each logging type. This requires the Asterisk executable to be present. ```bash asterisk -dddvvv ``` -------------------------------- ### Start Asterisk with Core Dump Option Source: https://docs.asterisk.org/Development/Debugging/Getting-a-Backtrace This command demonstrates how to start the Asterisk process with the '-g' option, which enables the generation of a core file if Asterisk crashes. This is a prerequisite for obtaining a backtrace. The safe_asterisk script automatically includes this option. ```bash asterisk -g ``` -------------------------------- ### ast_coredumper Configuration File Example Source: https://docs.asterisk.org/Development/Debugging/Getting-a-Backtrace An example of the ast_debug_tools.conf file used by Asterisk's debug tools, including ast_coredumper. This file specifies core dumps and search patterns. It must adhere to bash semantics as it is sourced by bash. ```bash # This file is used by the Asterisk debug tools. # Unlike other Asterisk config files, this one is # "sourced" by bash and must adhere to bash semantics. # # A list of coredumps and/or coredump search patterns. # Bash extended globs are enabled and any resulting files # that aren't actually coredumps are silently ignored # so you can be liberal with the globs. # # If your patterns contains spaces be sure to only quote ``` -------------------------------- ### Start Asterisk with Console and Verbosity Source: https://docs.asterisk.org/Getting-Started/Hello-World Starts the Asterisk service with an interactive control console and sets the verbosity level to 5. This is useful for real-time monitoring and debugging during startup. ```bash asterisk -cvvvvv ``` -------------------------------- ### Install LibPRI Library (Shell) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Prerequisites/Building-and-Installing-LibPRI Installs the compiled LibPRI library to the appropriate system library directory. This command should be executed after a successful compilation. ```shell [root@server libpri-1.X.Y]# make install ``` -------------------------------- ### SIP INVITE Request Example for Endpoint Identification Source: https://docs.asterisk.org/Configuration/Channel-Drivers/SIP/Configuring-res_pjsip/Asterisk-PJSIP-Troubleshooting-Guide An example of an incoming SIP INVITE request. Asterisk uses the 'From' header's user part (e.g., 'eggowaffles') to identify the endpoint. If no matching endpoint is found, the call is rejected. ```sip <--- Received SIP request (541 bytes) from UDP:127.0.0.1:5061 ---> INVITE sip:service@127.0.0.1:5060 SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:5061;branch=z9hG4bK-27600-1-0 From: breakfast ;tag=27600SIPpTag001 To: sut Call-ID: 1-27600@127.0.0.1 CSeq: 1 INVITE Contact: sip:eggowaffles@127.0.0.1:5061 Max-Forwards: 70 Content-Type: application/sdp Content-Length: 163 v=0 o=user1 53655765 2353687637 IN IP4 127.0.0.1 s=- c=IN IP4 127.0.0.1 t=0 0 m=audio 6000 RTP/AVP 0 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=ptime:20 ``` -------------------------------- ### Asterisk Module File Example Source: https://docs.asterisk.org/Fundamentals/Asterisk-Architecture/Asterisk-Architecture-The-Big-Picture Demonstrates the typical file extension for Asterisk modules and provides an example of a core module's naming convention. These modules are loaded by the Asterisk core to provide extended functionality. ```bash # Example of a module file *.so # Example of a core module file pbx_xxxxx.so ``` -------------------------------- ### SIP Geolocation Header Example (By Reference) Source: https://docs.asterisk.org/Deployment/Geolocation This example demonstrates how a SIP Geolocation header can be used to indicate a location description document by reference. The recipient is expected to retrieve the XML document from the provided URI. Asterisk itself does not retrieve information from these URIs. ```sip Geolocation: <> ``` -------------------------------- ### Asterisk Dialplan: Goto() Syntax Example Source: https://docs.asterisk.org/Latest_API/API_Documentation/Dialplan_Applications/Goto Demonstrates the basic syntax for the Goto() dialplan application. It shows how to specify context, extension, and priority, or just priority if the context and extension are the current ones. Arguments must be provided in the correct order. ```asterisk-dialplan Goto(context,extension,priority) Goto(extension,priority) Goto(priority) ``` -------------------------------- ### Shell Command: Backup and Edit extensions.conf Source: https://docs.asterisk.org/Getting-Started/Hello-World Backs up the existing extensions.conf file by renaming it to extensions.sample and then opens a new, blank extensions.conf file for editing using the Vim editor. This prepares the dialplan configuration. ```bash mv extensions.conf extensions.sample vim extensions.conf ``` -------------------------------- ### PJSIP Phone Provisioning Configuration Example (pjsip.conf) Source: https://docs.asterisk.org/Asterisk_18_Documentation/API_Documentation/Module_Configuration/res_pjsip_phoneprov_provider This snippet shows an example configuration for a user within the pjsip.conf file, demonstrating how to define phone provisioning parameters for a PJSIP endpoint. It includes required fields like MAC and PROFILE, as well as optional variables that are passed through to the phone provisioning system. ```ini [1000] type = phoneprovr endpoint = ep1000 MAC = deadbeef4dad PROFILE = grandstream2 LINEKEYS = 2 LINE = 1 OTHERVAR = othervalue ``` -------------------------------- ### AEAP Get API Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-External-Application-Protocol-AEAP Retrieves attributes, settings, and other data from a remote application after a successful setup. ```APIDOC ## POST /websites/asterisk/get ### Description Retrieves specified attributes and settings from the remote application. ### Method POST ### Endpoint /websites/asterisk/get ### Parameters #### Request Body - **request** (string) - Required - Must be 'get'. - **id** (string) - Required - A unique identifier for the request. - **params** (array) - Required - A list of parameter names to retrieve. - (string) - The name of the parameter to retrieve. ### Request Example ```json { "request": "get", "id": "f066e049-d4ef-4093-a05b-0effef1bc077", "params": [ "language" ] } ``` ### Response #### Success Response (200) - **response** (string) - Will be 'get'. - **id** (string) - The unique ID from the request. - **params** (object) - Key-value pairs of requested parameters and their values. - **name** (string) - The name of the parameter. - **value** (any) - The value of the parameter (type depends on the parameter). #### Response Example ```json { "response": "get", "id": "f066e049-d4ef-4093-a05b-0effef1bc077", "params": { "language": "en" } } ``` ``` -------------------------------- ### Asterisk Dialplan for Call Recording with MixMonitor Source: https://docs.asterisk.org/Fundamentals/Key-Concepts/Frames/Audiohooks This Asterisk dialplan snippet demonstrates the initial setup for recording calls using MixMonitor. It answers an incoming call, starts recording, and places the call into a queue. This basic setup will stop recording if an attended transfer occurs. ```asterisk exten => 1,1,Answer() exten => 1,n,MixMonitor(training_recording.wav) exten => 1,n,Queue(techsupport) ``` -------------------------------- ### PJSIP Phone Configuration Wizard Example Source: https://docs.asterisk.org/Asterisk_16_Documentation/API_Documentation/Module_Configuration/res_pjsip_config_wizard This configuration snippet demonstrates how to use the PJSIP Configuration Wizard to set up objects necessary for a phone to obtain provisioning information, register, and handle calls. It outlines parameters for authentication, registration, and hints. ```asterisk-config [myphone] type = wizard sends_auth = no accepts_auth = yes sends_registrations = no accepts_registrations = yes has_phoneprov = yes transport = ipv4 has_hint = yes hint_exten = 1000 inbound_auth/username = testname inbound_auth/password = test password endpoint/allow = ulaw endpoint/context = default phoneprov/MAC = 001122aa4455 phoneprov/PROFILE = profile1 ``` -------------------------------- ### Example: Removing and Replacing Hangup Handlers - Asterisk Dialplan Source: https://docs.asterisk.org/Configuration/Dialplan/Subroutines/Hangup-Handlers This example shows how to remove a hangup handler (hdlr1) and replace another (hdlr2 with hdlr4) using `CHANNEL(hangup_handler_pop)`. It starts by adding three handlers and then demonstrates the removal and replacement process, including the resulting handler definitions. ```asterisk-dialplan ; Some dialplan extension same => n,Set(CHANNEL(hangup_handler_push)=hdlr3,s,1(args)); same => n,Set(CHANNEL(hangup_handler_push)=hdlr2,s,1(args)); same => n,Set(CHANNEL(hangup_handler_push)=hdlr1,s,1(args)); ; Remove hdlr1 same => n,Set(CHANNEL(hangup_handler_pop)=) ; Replace hdlr2 with hdlr4 same => n,Set(CHANNEL(hangup_handler_pop)=hdlr4,s,1(args)); ; Continuing in some dialplan extension [hdlr1] exten => s,1,Verbose(0, Not Executed) same => n,Return() [hdlr2] exten => s,1,Verbose(0, Not Executed) same => n,Return() [hdlr3] exten => s,1,Verbose(0, Executed Second) same => n,Return() [hdlr4] exten => s,1,Verbose(0, Executed First) same => n,Return() ``` -------------------------------- ### Building Asterisk Documentation Source: https://docs.asterisk.org/Contributing-to-the-Documentation This command initiates the build process for the static Asterisk documentation. It assumes the environment is set up and dependencies are installed. ```bash $ make ``` -------------------------------- ### Handling Channel Events (StasisEnd) Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI This section covers the `StasisEnd` event, which is received when a channel leaves the Stasis application, typically when the call is hung up. ```APIDOC ## Handling Channel Events (StasisEnd) ### Description The `StasisEnd` event is generated by Asterisk when a channel terminates its engagement with a Stasis application. This event signals the end of the call leg within the application's context. ### Event Type `StasisEnd` ### Event Data Structure - **application** (string) - The name of the Stasis application. - **type** (string) - Always `StasisEnd` for this event. - **timestamp** (string) - The time the event occurred. - **channel** (object) - Details about the channel that is leaving Stasis. - **id** (string) - The unique identifier of the channel. - **state** (string) - The final state of the channel (e.g., `Up`). - **name** (string) - The name of the channel (e.g., `PJSIP/1000-00000001`). - **caller** (object) - Information about the caller. - **connected** (object) - Information about the connected party. - **accountcode** (string) - The account code associated with the channel. - **dialplan** (object) - Dialplan context, extension, and priority. - **creationtime** (string) - The time the channel was created. ### Event Example ```json { "application":"hello-world", "type":"StasisEnd", "timestamp":"2014-05-20T13:30:01.852-0500", "channel":{ "id":"1400609726.3", "state":"Up", "name":"PJSIP/1000-00000001", "caller":{ "name":"", "number":""}, "connected":{ "name":"", "number":""}, "accountcode":"", "dialplan":{ "context":"default", "exten":"1000", "priority":3}, "creationtime":"2014-05-20T13:15:26.628-0500"} } ``` ``` -------------------------------- ### Navigate to LibPRI Source Directory (Shell) Source: https://docs.asterisk.org/Getting-Started/Installing-Asterisk/Installing-Asterisk-From-Source/Prerequisites/Building-and-Installing-LibPRI Changes the current working directory to the extracted LibPRI source code directory. This is the first step before compilation. ```shell [root@server src]# cd libpri-1.X.Y ``` -------------------------------- ### Get IAX Peer Preferred Codec by Index Source: https://docs.asterisk.org/Certified-Asterisk_20.7_Documentation/API_Documentation/Dialplan_Functions/IAXPEER Retrieves a specific preferred codec for an IAX2 peer based on its index (starting from '0'). ```asterisk dialplan same => n, Set(PREFERRED_CODEC=${IAXPEER(peer10,codec[0])}) ``` -------------------------------- ### Recompile Asterisk with ODBC Modules Source: https://docs.asterisk.org/Configuration/Interfaces/Back-end-Database-and-Realtime-Connectivity/ODBC/Getting-Asterisk-Connected-to-MySQL-via-ODBC These commands are used to recompile Asterisk after installing necessary ODBC and MySQL components. It ensures that Asterisk includes the required ODBC modules for database integration. The process involves navigating to the source directory, running configure, and then performing make and make install. ```bash # cd ~/asterisk-source/ # ./configure # make && make install ``` -------------------------------- ### Get IAX Peer Specific Codec (Asterisk Dialplan) Source: https://docs.asterisk.org/Certified-Asterisk_18.9_Documentation/API_Documentation/Dialplan_Functions/IAXPEER Retrieves the preferred codec at a specific index for an IAX2 peer. Codecs are indexed starting from '0'. ```asterisk IAXPEER(peername,codec[x]) ``` -------------------------------- ### Install and Configure Radiusclient Library Source: https://docs.asterisk.org/Configuration/Reporting/Channel-Event-Logging-CEL/CEL-Configuration-Examples/RADIUS-CEL-Backend Steps to download, compile, and install the Radiusclient-ng library, along with essential configuration for authentication and accounting servers, and dictionary file inclusion. ```bash root@localhost:/usr/local/src# tar xvfz radiusclient-ng-0.5.2.tar.gz root@localhost:/usr/local/src# cd radiusclient-ng-0.5.2 root@localhost:/usr/local/src/radiusclient-ng-0.5.2#./configure root@localhost:/usr/local/src/radiusclient-ng-0.5.2# make root@localhost:/usr/local/src/radiusclient-ng-0.5.2# make install # Configuration examples: # authserver localhost # acctserver localhost # Add to /usr/local/etc/radiusclient-ng/dictionary: # $INCLUDE /path/to/dictionary.digium ``` -------------------------------- ### Asterisk chan_sip Template Example: Basic Options and Inheritance Source: https://docs.asterisk.org/Fundamentals/Asterisk-Configuration/Asterisk-Configuration-Files/Templates/Using-Templates A comprehensive example from the chan_sip configuration file, showcasing template definitions for basic options, natted phones, public phones, and codec preferences, along with inheritance. ```asterisk-config [basic-options](!) ; a template dtmfmode=rfc2833 context=from-office type=friend [natted-phone](!,basic-options) ; another template inheriting basic-options nat=yes directmedia=no host=dynamic [public-phone](!,basic-options) ; another template inheriting basic-options nat=no directmedia=yes [my-codecs](!) ; a template for my preferred codecs disallow=all allow=ilbc allow=g729 allow=gsm allow=g723 allow=ulaw [ulaw-phone](!) ; and another one for ulaw-only disallow=all allow=ulaw ; and finally instantiate a few phones ; ; [2133](natted-phone,my-codecs) ; secret = peekaboo ; [2134](natted-phone,ulaw-phone) ; secret = not_very_secret ; [2136](public-phone,ulaw-phone) ; secret = not_very_secret_either ``` -------------------------------- ### Playback Media on a Channel Source: https://docs.asterisk.org/Configuration/Interfaces/Asterisk-REST-Interface-ARI/Getting-Started-with-ARI This section demonstrates how to use the Asterisk ARI REST API to play a sound file to a specific channel that has entered the Stasis application. ```APIDOC ## Playback Media on a Channel ### Description Initiates playback of a media file (e.g., a sound) to a specified channel. This is typically done after receiving a `StasisStart` event. ### Method POST ### Endpoint `/ari/channels/{channelId}/play` ### Parameters #### Path Parameters - **channelId** (string) - Required - The unique identifier of the channel to play media to (e.g., `1400609726.3`). #### Query Parameters - **media** (string) - Required - The media to play, specified as a URI (e.g., `sound:hello-world`). ### Request Example ```bash curl -v -u asterisk:asterisk -X POST "http://localhost:8088/ari/channels/1400609726.3/play?media=sound:hello-world" ``` ### Response #### Success Response (201 Created) Returns a JSON object representing the created Playback resource. - **id** (string) - The unique identifier for this playback operation. - **media_uri** (string) - The media that was queued for playback. - **target_uri** (string) - The URI of the channel targeted for playback. - **language** (string) - The language code for the media playback. - **state** (string) - The current state of the playback (e.g., `queued`). #### Response Example ```json { "id":"9567ea46-440f-41be-a044-6ecc8100730a", "media_uri":"sound:hello-world", "target_uri":"channel:1400609726.3", "language":"en", "state":"queued"} ``` ### Events - **PlaybackStarted**: Sent when playback begins. - **PlaybackFinished**: Sent when playback completes. #### Event Example (PlaybackStarted) ```json { "application":"hello-world", "type":"PlaybackStarted", "playback":{ "id":"9567ea46-440f-41be-a044-6ecc8100730a", "media_uri":"sound:hello-world", "target_uri":"channel:1400609726.3", "language":"en", "state":"playing"} } ``` ```