Receive SMS
dowusu opened this issue · 2 comments
I would like to bind and receive SMS from a telecom SMSC. I've been going through the docs and it seems there are no docs for the function I suppose will allow me to do this, can educate me a bit on this aspect of your awesome library. Below is my code.
defmodule Bundle.Renewal do
use SMPPEX.Session
require Logger
def start_link() do
SMPPEX.ESME.start_link(Application.get_env(:bundle, :smsc), Application.get_env(:bundle, :smsc_port), {__MODULE__, []})
end
def init(_, _, _) do
SMPPEX.Pdu.Factory.bind_receiver("123", "123")
{:ok, nil}
end
def handle_pdu(pdu, state) do
Logger.info("#{inspect pdu}")
{:ok, state}
end
end
- Below is what I see in the logs.
info] Session #PID<0.545.0>, being stopped by timers(session_init_timer)
[info] Session #PID<0.545.0> stopped with reason: {:timers, :session_init_timer}, lost_pdus: []
[error] GenServer #PID<0.545.0> terminating
** (stop) {:timers, :session_init_timer}
Last message: {:check_timers, -576460219991}
State: %SMPPEX.TransportSession{buffer: "", module: SMPPEX.Session, module_state: %SMPPEX.Session{auto_pdu_handler: %SMPPEX.Session.AutoPduHandler{by_ref: #Reference<0.3437791628.3933863937.104761>, by_sequence_number: #Reference<0.3437791628.3933863937.104760>}, module: Bundle.Renewal, module_state: nil, pdus: %SMPPEX.PduStorage{by_sequence_number: #Reference<0.3437791628.3933863937.104759>}, response_limit: 60000, sequence_number: 0, tick_timer_ref: #Reference<0.3437791628.3933732865.105160>, time: -576460219991, timer_resolution: 100, timers: %SMPPEX.SMPPTimers{connection_time: -576460230091, enquire_link_limit: 30000, enquire_link_resp_limit: 30000, enquire_link_state: :active, inactivity_limit: :infinity, last_peer_action_time: 0, last_transaction_time: 0, session_init_limit: 10000, session_init_state: :established}}, ref: #Reference<0.3437791628.3933732865.104756>, socket: #Port<0.68>, transport: :ranch_tcp}
Thanks a lot for your support.
I manage to get this working with the below code. I'm still not sure if it's the right thing though.
defmodule Renewal do
use SMPPEX.Session
require Logger
@system_id "======="
@password "======="
def start_link do
SMPPEX.ESME.start_link("SMSC IP", SMSC_PORT, {__MODULE__, []}, [enquire_link_limit: 3000])
end
def init(_, _, _) do
send(self(), :bind)
{:ok, nil}
end
def handle_info(:bind, state) do
{:noreply,[SMPPEX.Pdu.Factory.bind_transceiver(@system_id, @password)], state}
end
def handle_pdu(pdu, state) do
Logger.info("#{inspect pdu}")
pdu =
case SMPPEX.Pdu.command_name(pdu) do
:deliver_sm ->
SMPPEX.Pdu.Factory.deliver_sm_resp
:enquire_link ->
SMPPEX.Pdu.Factory.enquire_link_resp
end
{:ok, [pdu], state}
end
end
Resources on SMPP is quite scanty, this library is awesome and I feel a lot of documentation will go a long way to help newbies like me. Kindly advise on the above if it will suffice to be used as an sms client to handle messages from the SMSC and process it.
Hello!
Not sure this is correct:
pdu =
case SMPPEX.Pdu.command_name(pdu) do
:deliver_sm ->
SMPPEX.Pdu.Factory.deliver_sm_resp
:enquire_link ->
SMPPEX.Pdu.Factory.enquire_link_resp
end
{:ok, [pdu], state}
One should identify that newly generated pdu
is the response to the original pdu, i.e. something like that:
resp_pdu =
case SMPPEX.Pdu.command_name(pdu) do
:deliver_sm ->
SMPPEX.Pdu.Factory.deliver_sm_resp(0) |> SMPPEX.Pdu.as_reply_to(pdu)
:enquire_link ->
SMPPEX.Pdu.Factory.enquire_link_resp(0) |> SMPPEX.Pdu.as_reply_to(pdu)
end
{:ok, [resp_pdu], state}
Also, enquire_link
-s are handled internally by th library, there is no need to handle them.