Send SMS to SIPSTATION gateway from Asterisk AMI

I’ve been testing some POC code and system architecture I’ve designed to make responding to SMS received from SIPSTATION gateway easier and more mobile than having to log into UCP to do so.

I’ve already written automation to scrape the asterisk sms tables in the database (in the future an event-driven model would be better) and email to me every few seconds.

The easiest way I’ve found to respond would be to reply to said email. I operate my own email relay and freepbx server. The emails sent from scraping are sent as an authenticated user on my relay with proper dkim/spf, etc. I have the relay set up to redirect all emails sent to that specific user (in this case all replies to said scrape emails) to the asterisk system, which runs a basic smtp routine i wrote to process the email and handoff to some sort of Asterisk AMI routine (written in php). The goal is to find a way to query Asterisk AMI (or some other method) to send an SMS to the SIPSTATION gateway i use.

the following snippet works, so I’m able to connect to AMI and issue commands

$asm = new AGI_AsteriskManager();
if($asm->connect('', 'username', 'password')) {
    $peers = $asm->command("sip show peers");

However, I can’t seem to call the MessageSend method without failure, provided this is what I will need to call.

$asm = new AGI_AsteriskManager();
if($asm->connect('', 'username', 'password')) {
    $result = $asm->MessageSend('sip:19999999999', '"Caller ID Name" <19999999999>', 'hello');

[Response] => Error
[Message] => Message failed to send.

asterisk cli debug logs show:

[2022-04-23 23:30:43] WARNING[31990]: chan_sip.c:6331 create_addr: Purely numeric hostname (19999999999), and not a peer–rejecting!

My initial reading material is from here:

Is it possible for me to send an SMS message out to a 10 digit cell number like this?

UCP doesn’t exist in Asterisk; it’s part of FreePBX. Did you mean to post this to

This is not a well formed SIP URI. chan_sip is deprecated, unsupported, and will be removed next year.

The URI part of this is not well formed.

Interesting. It looks like the documentation is incomplete (not surprising), as the possibility of using a peer name isn’t mentioned. However, as the message says, this isn’t a valid peer name and also isn’t a valid domain name, so there is no way of finding the domain name of of the SMS gateway. Message Send sends a SIP message, it does not send a mobile phone message. SIP messages are always sent to SIP URIs, not phone numbers (and Asterisk doesn’t support tel: URIs).

The documentation I am using is: Asterisk 16 Application_MessageSend - Asterisk Project - Asterisk Project Wiki

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.