Is there a way to send a SMS message to IP using sockets when extension is dialed?
this is Python code:
#!/usr/bin/env python3
import time
import socket, sys
def sendMessage(msg): # Calling function
try:
print(msg)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = “...” # Get local machine name
port = ***** # Reserve a port for your service.
s.connect((host, port)) # Bind to the port
s.send(msg.encode())
print(“Message sent”)
from_server = s.recv(4096)
s.close()
except:
print(sys.exc_info()[0])
when 302 is dialed sendMessage(“Input 1”)
when 302 is hungup sendMessage(“Input 1 Off”)
when 303 is dialed sendMessage(“Input 2”)
when 303 is hungup sendMessage(“Input 2 Off”)
when 304 is dialed sendMessage(“Input 3”)
when 304 is hungup sendMessage(“Input 3 Off”)
Asterisk has built-in functions for sending messages. Do you really mean something like SMS (in SIP, it would be SIP MESSAGE method), which can be done directly through dialplan, or do you mean custom network messages that are not SIP?
This does not make any sense, so you need to refine it. SMS has meaning on the cellular phone network but it does not seem like that’s what you really mean.
Do you want to do some network socket low-level stuff or do you want to send a SIP MESSAGE?
If you want to send a SIP message, here’s the basic outline.
Define an extension (PJSIP or SIP) in FreePBX to receive your message.
If you don’t want to do a SIP MESSAGE but instead some other kind of socket, you can call your python script from the dialplan instead (Home - Asterisk Documentation).
In FreePBX, any custom dialplan you want to create can be done in the file /etc/asterisk/extensions_custom.conf
From there, you can create or extend the context [from-internal-custom] to create custom dialplan that is available from FreePBX phones/extensions.
There is nothing built into the web interface to allow you to run custom Python modules. The “custom” file and likewise the “custom” contexts in the dialplan are there to allow you to add this kind of advanced scripting.