Class: Smpp::Transceiver
- Defined in:
- lib/smpp/transceiver.rb
Overview
The SMPP Transceiver maintains a bidirectional connection to an SMSC. Provide a config hash with connection options to get started. See the sample_gateway.rb for examples of config values. The transceiver accepts a delegate object that may implement the following (all optional) methods:
mo_received(transceiver, pdu)
delivery_report_received(transceiver, pdu)
(transceiver, , pdu)
(transceiver, , pdu)
bound(transceiver)
unbound(transceiver)
Constant Summary
Constants included from Smpp
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.get_message_part_size(options) ⇒ Object
Use data_coding to find out what message part size we can use en.wikipedia.org/wiki/SMS#Message_size.
Instance Method Summary collapse
-
#send_bind ⇒ Object
Send BindTransceiverResponse PDU.
-
#send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) ⇒ Object
Send a concatenated message with a body of > 160 characters as multiple messages.
-
#send_mt(message_id, source_addr, destination_addr, short_message, options = {}) ⇒ Object
Send an MT SMS message.
-
#send_multi_mt(message_id, source_addr, destination_addr_arr, short_message, options = {}) ⇒ Object
Send MT SMS message for multiple dest_address Author: Abhishek Parolkar (abhishekparolkar.com) USAGE: $tx.send_multi_mt(123, “9100000000”, [“9199000000000”,“91990000000001”,“9199000000002”], “Message here”).
Methods inherited from Base
#bound?, #initialize, #logger, logger, logger=, #post_init, #process_pdu, #receive_data, #run_callback, #send_unbind, #start_enquire_link_timer, #unbind, #unbound?
Constructor Details
This class inherits a constructor from Smpp::Base
Class Method Details
.get_message_part_size(options) ⇒ Object
Use data_coding to find out what message part size we can use en.wikipedia.org/wiki/SMS#Message_size
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/smpp/transceiver.rb', line 99 def self. return 153 if [:data_coding].nil? return 153 if [:data_coding] == 0 return 134 if [:data_coding] == 3 return 134 if [:data_coding] == 5 return 134 if [:data_coding] == 6 return 134 if [:data_coding] == 7 return 67 if [:data_coding] == 8 return 153 end |
Instance Method Details
#send_bind ⇒ Object
Send BindTransceiverResponse PDU.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/smpp/transceiver.rb', line 85 def send_bind raise IOError, 'Receiver already bound.' unless unbound? pdu = Pdu::BindTransceiver.new( @config[:system_id], @config[:password], @config[:system_type], @config[:source_ton], @config[:source_npi], @config[:source_address_range]) write_pdu(pdu) end |
#send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) ⇒ Object
Send a concatenated message with a body of > 160 characters as multiple messages.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/smpp/transceiver.rb', line 33 def send_concat_mt(, source_addr, destination_addr, , = {}) logger.debug "Sending concatenated MT: #{}" if @state == :bound # Split the message into parts of 153 characters. (160 - 7 characters for UDH) parts = [] while .size > 0 do parts << .slice!(0..Smpp::Transceiver.()) end 0.upto(parts.size-1) do |i| udh = sprintf("%c", 5) # UDH is 5 bytes. udh << sprintf("%c%c", 0, 3) # This is a concatenated message #TODO Figure out why this needs to be an int here, it's a string elsewhere udh << sprintf("%c", ) # The ID for the entire concatenated message udh << sprintf("%c", parts.size) # How many parts this message consists of udh << sprintf("%c", i+1) # This is part i+1 [:esm_class] = 64 # This message contains a UDH header. [:udh] = udh pdu = Pdu::SubmitSm.new(source_addr, destination_addr, parts[i], ) write_pdu pdu # This is definately a bit hacky - multiple PDUs are being associated with a single # message_id. @ack_ids[pdu.sequence_number] = end else raise InvalidStateException, "Transceiver is unbound. Connot send MT messages." end end |
#send_mt(message_id, source_addr, destination_addr, short_message, options = {}) ⇒ Object
Send an MT SMS message. Delegate will receive message_accepted callback when SMSC acknowledges, or the message_rejected callback upon error
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smpp/transceiver.rb', line 18 def send_mt(, source_addr, destination_addr, , ={}) logger.debug "Sending MT: #{}" if @state == :bound pdu = Pdu::SubmitSm.new(source_addr, destination_addr, , ) write_pdu pdu # keep the message ID so we can associate the SMSC message ID with our message # when the response arrives. @ack_ids[pdu.sequence_number] = else raise InvalidStateException, "Transceiver is unbound. Cannot send MT messages." end end |
#send_multi_mt(message_id, source_addr, destination_addr_arr, short_message, options = {}) ⇒ Object
Send MT SMS message for multiple dest_address Author: Abhishek Parolkar (abhishekparolkar.com) USAGE: $tx.send_multi_mt(123, “9100000000”, [“9199000000000”,“91990000000001”,“9199000000002”], “Message here”)
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/smpp/transceiver.rb', line 70 def send_multi_mt(, source_addr, destination_addr_arr, , ={}) logger.debug "Sending Multiple MT: #{}" if @state == :bound pdu = Pdu::SubmitMulti.new(source_addr, destination_addr_arr, , ) write_pdu pdu # keep the message ID so we can associate the SMSC message ID with our message # when the response arrives. @ack_ids[pdu.sequence_number] = else raise InvalidStateException, "Transceiver is unbound. Cannot send MT messages." end end |