Send SMS through SIPSTATION gateway from Asterisk AMI

I posted this in asterisk’s forums but was told this was something I should post here

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 through 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('127.0.0.1', 'username', 'password')) {
    $peers = $asm->command("sip show peers");
    print_r($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('127.0.0.1', 'username', 'password')) {
    $result = $asm->MessageSend('sip:19999999999', '"Caller ID Name" <19999999999>', 'hello');
    print_r($result);
}

Array
(
[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!

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

You were referred here because your first paragraph mentioned using UCP. However, that reply, also explained what was wrong with your message send and why you were getting the all numeric hostname warning.

I should also point out that you should no longer be using chan_sip, as it is deprecated, unsupported, and will be removed in next year’s release of Asterisk.

In an attempt to merge other threads, I accidentally messed up this one. It’s corrected now; my apologies for any confusion.

Outbound SMS messages using SIPStation do not use MessageSend, or Asterisk dialplan at all. Outbound is done with https API calls that are not public. Inbound SMS from SIPStation does arrive as a SIP MESSAGE, and are processed with the FreePBX AGI.

At present there is no supported way to support sending the way you want, but there is something in development now that will do it. Stay tuned.

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