SlideShare a Scribd company logo
ASYNCHRONOUS
SMS MESSAGING
WITH RUBY
-Vaggelis Typaldos @vtypal
OVERVIEW
SMS
Short Message Service
What is?
Why use it?
SMS PROS
Sms is easy
Sms is available to everybody
Sms is a high revenue communication channel
SMS CONS
Sms is short (plain text of 160 chars max.)
Send sms is not cost free
Sms black hours
Legal conditions
SMSC
Short Message Service Center
Send and receive SMS & DLRs
Check msisdn to HLR database
Assign a short code (4-digit) number to our bind
Set throughput (sms rate)
SMSC talks to (ESME) clients via SMPP protocol
SMPP PROTOCOL (V_3.4)
Short Message Peerto PeerProtocol
Peer to peer over tcp protocol between ESME (external short
messaging entities) clients and SMSC for sending/receiving SMS
messages.
Each tcp packet is called PDU (Protocol Data Unit)
bind_sm/bind_sm_resp
enquire_link/enquire_link_resp
submit_sm/submit_sm_resp
deliver_sm/deliver_sm_resp
TYPICALSMPP REQUEST - RESPONSE
KANNEL SMS GATEWAY
PROS
Open source
Fast and Light
Single configuration file
Local store for sms
Split long text messages in more parts
Rich API
KANNEL.CONF (BEARERBOX)
group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
store-location = "/app/gateway-1.5.0/logs/kannel.store"
# SMSC SMPP
group = smsc
smsc = smpp
smsc-id = "smsc"
host = 10.10.10.10
port = 9000
system-type = ESME
smsc-username = "2222"
smsc-password = "2222pass"
transceiver-mode = true
source-addr-ton = 0
source-addr-npi = 1
interface-version = 34
dest-addr-ton = 1
dest-addr-npi = 5
max-pending-submits = 50
throughput = 50
#no-dlr=true
KANNEL.CONF (SMSBOX)
group = smsbox
bearerbox-host = localhost
sendsms-port = 13006
mo-recode = true
http-request-retry = 3
# SEND-SMS USERS
group = sendsms-user
username = tester
password = foobar
# SERVICES
group = sms-service
#max-messages = 10
get-url = http://appserver:8000/myapp/mo?from=%p&to=%P&text=%a&kcod=%c
&kchar=%C&smsc=%i&time=%t
accepted-smsc = smsc
RECEIVING MO
Mobile Originated
Retrieve the parameters defined in get-url(or post-url) of kannel.conf
http://appserver:8000/myapp/mo?
from=%p&to=%P&text=%a&kcod=%c&kchar=%C&smsc=%i&time=%t
class MyApp
def mo
if request.get?
@params=request.params
return %|
============ MO received at #{ @params['time'] } ============
From: #{ @params['from'] }
To; #{ @params['to'] }
Smsc: #{ @params['smsc'] }
Message: #{ @params['text'] }
==================================
|
end
end
end
SENDING MT
Mobile Terminated
GET request to the sendsms port of smsbox defined in kannel.conf
Try it using your browser (will work)
In your ruby code you must url encode the text
http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t
ester&password=foobar
&text=Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love R
uby (among other things)
and meet regularly in Athens in order to discuss and present on all things Rub
y.... and have beers,ouzo,
tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages.
&smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0
URI.ENCODE_WWW_FORM_COMPONENT(TEXT)
Athens+Ruby+Meetup+%28Athens.rb%29+is+a+group+of+%28not+just%29+geeks+
who+love+Ruby+%28among+other+things%29%0Aand+
meet+regularly+in+Athens+in+order+to+discuss+
and+present+on+all+things+Ruby...+and+have+
beers%2Couzo%2C%0Atsipouro+as+well+as+other+
alcoholic+%28and+sometimes+non-alcoholic%29+beverages.
MT example
require 'uri'
require 'net/http'
uri = URI.parse('http://smsgateway:13006/cgi-bin/sendsms'),
params = { :to => "306941234567", :from => "1234",
:username=>"tester", :password=>"foobar",
:text=>"Athens Ruby Meetup (Athens.rb) is a group of
(not just) geeks who love Ruby (among other things) and
meet regularly in Athens in order to discuss and present
on all things Ruby.... and have beers,ouzo,
tsipouro as well as other alcoholic (and sometimes
non-alcoholic) beverages.", etc }
# Add params to URI
uri.query = URI.encode_www_form( params )
puts Net::HTTP.get(uri)
REQUESTING DELIVERY REPORTS
dlr-url (url-encoded)
dlr-mask
http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t
ester&password=foobar
&text=Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love R
uby (among other things)
and meet regularly in Athens in order to discuss and present on all things Rub
y.... and have beers,ouzo,
tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages.
&smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0&
dlr-url=http://smsgateway:8000/myapp/dlr?msgId=22186231&type=%d&dlr-mask=3
http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t
ester&password=foobar
&text=Athens+Ruby+Meetup+%28Athens.rb%29+is+a+group+of+%28not+just%29+geeks+
who+love+Ruby+%28among+other+things%29%0Aand+
meet+regularly+in+Athens+in+order+to+discuss+
and+present+on+all+things+Ruby...+and+have+
beers%2Couzo%2C%0Atsipouro+as+well+as+other+
alcoholic+%28and+sometimes+non-alcoholic%29+beverages.
&smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0&
dlr-url=http%3A%2F%2Fsmsgateway%3A8000%2Fmyapp%2Fdlr%3FmsgId%3D22186231%26type
%3D%25&dlr-mask=3
MT with DLR example
require 'uri'
require 'net/http'
uri = URI.parse('http://smsgateway:13006/cgi-bin/sendsms'),
params = { :to => "306941234567", :from => "1234",
:username=>"tester", :password=>"foobar",
:text=>"Athens Ruby Meetup (Athens.rb) is a group of
(not just) geeks who love Ruby (among other things) and
meet regularly in Athens in order to discuss and present
on all things Ruby.... and have beers,ouzo,
tsipouro as well as other alcoholic (and sometimes
non-alcoholic) beverages.", etc..,
:dlr-url => "http://smsgateway:8000/myapp/dlr?msgId=22186231&type=%d",
:dlr-mask =>3 }
# Add params to URI
uri.query = URI.encode_www_form( params )
puts Net::HTTP.get(uri)
RECEIVING DLR
class MyApp
...
def dlr
if request.get?
@params=request.params
return %|
============ DLR received ============
Message Id:: #{ @params['msgId'] }
Delivery type: #{ @params['type'] }
==================================
|
end
end
end
MESSAGE BROKER
provides clients with connectivity, and message storage/delivery
functions
Queue: Destination that contains messages sent from a producer
that await delivery to one consumer
Destination: queues or topics
CLIENT TYPES
Producers (create messages and send or publish them to the broker
for delivery to a specified destination)
Consumers (retrieve messages from a destination)
MESSAGE BROKER PROS
Clustering
Failover
Persistence
STOMP
StreamingText OrientedMessagingProtocol (STOMP)
In activemq.xml configuration file replace the default wire protocol
used by native Java Message Broker clients with stomp transport
connector that supports clients written in languages such as Ruby,
Perl, Python, and PHP.
transportConnector name="openwire" uri="tcp://localhos
t:61616"
transportConnector name="stomp" uri="stomp://localhost
:61616"
PRODUCER-PUBLISHER
#Create the queue (if does not exist)
# and populate the queue with messages
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61616"
1.upto(50) do
client.publish("/queue/rbq", Time.now.strftime("%H-%M-%s"), { :persistent =
> true })
# client.publish("/topic/chat", "Hello Rubystes!", { :persistent => true })
sleep 2
end
client.close
CONSUMER-SUBSCRIBER
require 'stomp'
client = Stomp::Client.open "stomp://localhost:61616"
client.subscribe "/queue/rbq" do |message|
puts "received: #{message.body} on #{message.headers['destination']}"
end
client.join
client.close
ACTIMEMQ ADMIN UI
THE END
BYVTYPAL
Asynchronous sms messaging with Ruby

More Related Content

Similar to Asynchronous sms messaging with Ruby

Socket programming
Socket programmingSocket programming
Socket programming
Anurag Tomar
 
Augmenting Web Services with SMS and XMPP
Augmenting Web Services with SMS and XMPPAugmenting Web Services with SMS and XMPP
Augmenting Web Services with SMS and XMPP
Sam Keen
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
Mohammad Reza Kamalifard
 
ScavengerEXA
ScavengerEXAScavengerEXA
ScavengerEXA
Thomas Mangin
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
sureshkarthick37
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
Nadia Nahar
 
Http api 3.0.1 smsgatewayuhb
Http api 3.0.1   smsgatewayuhbHttp api 3.0.1   smsgatewayuhb
Http api 3.0.1 smsgatewayuhb
Siteadda Labs Technologies LLP
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Bart Uelen
 
EmailTracing.ppt
EmailTracing.pptEmailTracing.ppt
EmailTracing.ppt
govindanonymous143
 
Ruby
RubyRuby
Webservices
WebservicesWebservices
Webservices
Nyros Technologies
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute
 
Develop webservice in PHP
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHP
Sanil Subhash Chandra Bose
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
danwrong
 
Tt subtemplates-caching
Tt subtemplates-cachingTt subtemplates-caching
Tt subtemplates-caching
Valeriy Studennikov
 
uerj201212
uerj201212uerj201212
uerj201212
Juan Lopes
 
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
ClubHack
 
AntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the uglyAntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the ugly
amiable_indian
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
Frank Lyaruu
 
Network programming
Network programmingNetwork programming

Similar to Asynchronous sms messaging with Ruby (20)

Socket programming
Socket programmingSocket programming
Socket programming
 
Augmenting Web Services with SMS and XMPP
Augmenting Web Services with SMS and XMPPAugmenting Web Services with SMS and XMPP
Augmenting Web Services with SMS and XMPP
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
ScavengerEXA
ScavengerEXAScavengerEXA
ScavengerEXA
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
 
Http api 3.0.1 smsgatewayuhb
Http api 3.0.1   smsgatewayuhbHttp api 3.0.1   smsgatewayuhb
Http api 3.0.1 smsgatewayuhb
 
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
Tadhack madrid June 2014: Joris Swinnen and WebRTC Nederland "Invite my colle...
 
EmailTracing.ppt
EmailTracing.pptEmailTracing.ppt
EmailTracing.ppt
 
Ruby
RubyRuby
Ruby
 
Webservices
WebservicesWebservices
Webservices
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Develop webservice in PHP
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHP
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Tt subtemplates-caching
Tt subtemplates-cachingTt subtemplates-caching
Tt subtemplates-caching
 
uerj201212
uerj201212uerj201212
uerj201212
 
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
Aseem - AntiSpam - Understanding the good, the bad and the ugly - ClubHack2008
 
AntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the uglyAntiSpam - Understanding the good, the bad and the ugly
AntiSpam - Understanding the good, the bad and the ugly
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Network programming
Network programmingNetwork programming
Network programming
 

Recently uploaded

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 

Recently uploaded (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 

Asynchronous sms messaging with Ruby

  • 4. SMS PROS Sms is easy Sms is available to everybody Sms is a high revenue communication channel
  • 5. SMS CONS Sms is short (plain text of 160 chars max.) Send sms is not cost free Sms black hours Legal conditions
  • 6. SMSC Short Message Service Center Send and receive SMS & DLRs Check msisdn to HLR database Assign a short code (4-digit) number to our bind Set throughput (sms rate) SMSC talks to (ESME) clients via SMPP protocol
  • 7. SMPP PROTOCOL (V_3.4) Short Message Peerto PeerProtocol Peer to peer over tcp protocol between ESME (external short messaging entities) clients and SMSC for sending/receiving SMS messages. Each tcp packet is called PDU (Protocol Data Unit) bind_sm/bind_sm_resp enquire_link/enquire_link_resp submit_sm/submit_sm_resp deliver_sm/deliver_sm_resp
  • 9. KANNEL SMS GATEWAY PROS Open source Fast and Light Single configuration file Local store for sms Split long text messages in more parts Rich API
  • 10. KANNEL.CONF (BEARERBOX) group = core admin-port = 13000 smsbox-port = 13001 admin-password = bar store-location = "/app/gateway-1.5.0/logs/kannel.store" # SMSC SMPP group = smsc smsc = smpp smsc-id = "smsc" host = 10.10.10.10 port = 9000 system-type = ESME smsc-username = "2222" smsc-password = "2222pass" transceiver-mode = true source-addr-ton = 0 source-addr-npi = 1 interface-version = 34 dest-addr-ton = 1 dest-addr-npi = 5 max-pending-submits = 50 throughput = 50 #no-dlr=true
  • 11. KANNEL.CONF (SMSBOX) group = smsbox bearerbox-host = localhost sendsms-port = 13006 mo-recode = true http-request-retry = 3 # SEND-SMS USERS group = sendsms-user username = tester password = foobar # SERVICES group = sms-service #max-messages = 10 get-url = http://appserver:8000/myapp/mo?from=%p&to=%P&text=%a&kcod=%c &kchar=%C&smsc=%i&time=%t accepted-smsc = smsc
  • 12. RECEIVING MO Mobile Originated Retrieve the parameters defined in get-url(or post-url) of kannel.conf http://appserver:8000/myapp/mo? from=%p&to=%P&text=%a&kcod=%c&kchar=%C&smsc=%i&time=%t
  • 13. class MyApp def mo if request.get? @params=request.params return %| ============ MO received at #{ @params['time'] } ============ From: #{ @params['from'] } To; #{ @params['to'] } Smsc: #{ @params['smsc'] } Message: #{ @params['text'] } ================================== | end end end
  • 14. SENDING MT Mobile Terminated GET request to the sendsms port of smsbox defined in kannel.conf Try it using your browser (will work) In your ruby code you must url encode the text http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t ester&password=foobar &text=Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love R uby (among other things) and meet regularly in Athens in order to discuss and present on all things Rub y.... and have beers,ouzo, tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages. &smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0
  • 16. MT example require 'uri' require 'net/http' uri = URI.parse('http://smsgateway:13006/cgi-bin/sendsms'), params = { :to => "306941234567", :from => "1234", :username=>"tester", :password=>"foobar", :text=>"Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love Ruby (among other things) and meet regularly in Athens in order to discuss and present on all things Ruby.... and have beers,ouzo, tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages.", etc } # Add params to URI uri.query = URI.encode_www_form( params ) puts Net::HTTP.get(uri)
  • 17. REQUESTING DELIVERY REPORTS dlr-url (url-encoded) dlr-mask http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t ester&password=foobar &text=Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love R uby (among other things) and meet regularly in Athens in order to discuss and present on all things Rub y.... and have beers,ouzo, tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages. &smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0& dlr-url=http://smsgateway:8000/myapp/dlr?msgId=22186231&type=%d&dlr-mask=3 http://smsgateway:13006/cgi-bin/sendsms?to=30306941234567&from=1234&username=t ester&password=foobar &text=Athens+Ruby+Meetup+%28Athens.rb%29+is+a+group+of+%28not+just%29+geeks+ who+love+Ruby+%28among+other+things%29%0Aand+ meet+regularly+in+Athens+in+order+to+discuss+ and+present+on+all+things+Ruby...+and+have+ beers%2Couzo%2C%0Atsipouro+as+well+as+other+ alcoholic+%28and+sometimes+non-alcoholic%29+beverages. &smsc=smsc&coding=0&charset=UTF-8&alt-dcs=0& dlr-url=http%3A%2F%2Fsmsgateway%3A8000%2Fmyapp%2Fdlr%3FmsgId%3D22186231%26type %3D%25&dlr-mask=3
  • 18. MT with DLR example require 'uri' require 'net/http' uri = URI.parse('http://smsgateway:13006/cgi-bin/sendsms'), params = { :to => "306941234567", :from => "1234", :username=>"tester", :password=>"foobar", :text=>"Athens Ruby Meetup (Athens.rb) is a group of (not just) geeks who love Ruby (among other things) and meet regularly in Athens in order to discuss and present on all things Ruby.... and have beers,ouzo, tsipouro as well as other alcoholic (and sometimes non-alcoholic) beverages.", etc.., :dlr-url => "http://smsgateway:8000/myapp/dlr?msgId=22186231&type=%d", :dlr-mask =>3 } # Add params to URI uri.query = URI.encode_www_form( params ) puts Net::HTTP.get(uri)
  • 19. RECEIVING DLR class MyApp ... def dlr if request.get? @params=request.params return %| ============ DLR received ============ Message Id:: #{ @params['msgId'] } Delivery type: #{ @params['type'] } ================================== | end end end
  • 20. MESSAGE BROKER provides clients with connectivity, and message storage/delivery functions Queue: Destination that contains messages sent from a producer that await delivery to one consumer Destination: queues or topics CLIENT TYPES Producers (create messages and send or publish them to the broker for delivery to a specified destination) Consumers (retrieve messages from a destination)
  • 22. STOMP StreamingText OrientedMessagingProtocol (STOMP) In activemq.xml configuration file replace the default wire protocol used by native Java Message Broker clients with stomp transport connector that supports clients written in languages such as Ruby, Perl, Python, and PHP. transportConnector name="openwire" uri="tcp://localhos t:61616" transportConnector name="stomp" uri="stomp://localhost :61616"
  • 23. PRODUCER-PUBLISHER #Create the queue (if does not exist) # and populate the queue with messages require 'stomp' client = Stomp::Client.open "stomp://localhost:61616" 1.upto(50) do client.publish("/queue/rbq", Time.now.strftime("%H-%M-%s"), { :persistent = > true }) # client.publish("/topic/chat", "Hello Rubystes!", { :persistent => true }) sleep 2 end client.close
  • 24. CONSUMER-SUBSCRIBER require 'stomp' client = Stomp::Client.open "stomp://localhost:61616" client.subscribe "/queue/rbq" do |message| puts "received: #{message.body} on #{message.headers['destination']}" end client.join client.close