Software /
code /
prosody-modules
Comparison
mod_sms_clickatell/mod_sms_clickatell.lua @ 1343:7dbde05b48a9
all the things: Remove trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Tue, 11 Mar 2014 18:44:01 +0100 |
parent | 1321:3fd6579d60cc |
child | 2448:1f7f66272f73 |
comparison
equal
deleted
inserted
replaced
1342:0ae065453dc9 | 1343:7dbde05b48a9 |
---|---|
1 -- mod_sms_clickatell | 1 -- mod_sms_clickatell |
2 -- | 2 -- |
3 -- A Prosody module for sending SMS text messages from XMPP using the | 3 -- A Prosody module for sending SMS text messages from XMPP using the |
4 -- Clickatell gateway's HTTP API | 4 -- Clickatell gateway's HTTP API |
5 -- | 5 -- |
6 -- Hacked from mod_twitter by Phil Stewart, March 2011. Anything from | 6 -- Hacked from mod_twitter by Phil Stewart, March 2011. Anything from |
7 -- mod_twitter copyright The Guy Who Wrote mod_twitter. Everything else | 7 -- mod_twitter copyright The Guy Who Wrote mod_twitter. Everything else |
8 -- copyright 2011 Phil Stewart. Licensed under the same terms as Prosody | 8 -- copyright 2011 Phil Stewart. Licensed under the same terms as Prosody |
9 -- (MIT license, as per below) | 9 -- (MIT license, as per below) |
210 module.log("info", "Clickatell API interaction function triggered"); | 210 module.log("info", "Clickatell API interaction function triggered"); |
211 -- Don't attempt to send an SMS with a null or empty message | 211 -- Don't attempt to send an SMS with a null or empty message |
212 if message == nil or message == "" then | 212 if message == nil or message == "" then |
213 return false; | 213 return false; |
214 end | 214 end |
215 | 215 |
216 local sms_message = sms_message_prefix..message; | 216 local sms_message = sms_message_prefix..message; |
217 local clickatell_base_url = "https://api.clickatell.com/http/sendmsg"; | 217 local clickatell_base_url = "https://api.clickatell.com/http/sendmsg"; |
218 local params = {user=user.data.username, password=user.data.password, api_id=user.data.api_id, from=user.data.source_number, to=number, text=sms_message}; | 218 local params = {user=user.data.username, password=user.data.password, api_id=user.data.api_id, from=user.data.source_number, to=number, text=sms_message}; |
219 local query_string = ""; | 219 local query_string = ""; |
220 | 220 |
288 end | 288 end |
289 --]] | 289 --]] |
290 | 290 |
291 -- XMPP Register callback | 291 -- XMPP Register callback |
292 -- The client must register with the gateway. In this case, the gateway is | 292 -- The client must register with the gateway. In this case, the gateway is |
293 -- Clickatell's http api, so we | 293 -- Clickatell's http api, so we |
294 function iq_register(origin, stanza) | 294 function iq_register(origin, stanza) |
295 module:log("info", "Register event triggered"); | 295 module:log("info", "Register event triggered"); |
296 if stanza.attr.type == "get" then | 296 if stanza.attr.type == "get" then |
297 local reply = data_cache.registration_form; | 297 local reply = data_cache.registration_form; |
298 if reply == nil then | 298 if reply == nil then |
450 if users[from_bjid].data.roster[to.node] ~= nil then | 450 if users[from_bjid].data.roster[to.node] ~= nil then |
451 origin.send(st.presence({to=from_bjid, from=to_bjid})); | 451 origin.send(st.presence({to=from_bjid, from=to_bjid})); |
452 end | 452 end |
453 end | 453 end |
454 | 454 |
455 | 455 |
456 return true; | 456 return true; |
457 end | 457 end |
458 | 458 |
459 --[[ Not using this ATM | 459 --[[ Not using this ATM |
460 function confirm_message_delivery(event) | 460 function confirm_message_delivery(event) |
511 | 511 |
512 -- Component event handler | 512 -- Component event handler |
513 function sms_event_handler(origin, stanza) | 513 function sms_event_handler(origin, stanza) |
514 module:log("debug", "Received stanza: "..stanza:pretty_print()); | 514 module:log("debug", "Received stanza: "..stanza:pretty_print()); |
515 local to_node, to_host, to_resource = jid_split(stanza.attr.to); | 515 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
516 | 516 |
517 -- Handle component internals (stanzas directed to component host, mainly iq stanzas) | 517 -- Handle component internals (stanzas directed to component host, mainly iq stanzas) |
518 if to_node == nil then | 518 if to_node == nil then |
519 local type = stanza.attr.type; | 519 local type = stanza.attr.type; |
520 if type == "error" or type == "result" then return; end | 520 if type == "error" or type == "result" then return; end |
521 if stanza.name == "presence" then | 521 if stanza.name == "presence" then |
543 iq_register(origin, stanza); | 543 iq_register(origin, stanza); |
544 return true; | 544 return true; |
545 end | 545 end |
546 end | 546 end |
547 end | 547 end |
548 | 548 |
549 -- Handle presence (both component and SMS users) | 549 -- Handle presence (both component and SMS users) |
550 if stanza.name == "presence" then | 550 if stanza.name == "presence" then |
551 presence_stanza_handler(origin, stanza); | 551 presence_stanza_handler(origin, stanza); |
552 end | 552 end |
553 | 553 |
554 -- Handle messages (both component and SMS users) | 554 -- Handle messages (both component and SMS users) |
555 if stanza.name == "message" then | 555 if stanza.name == "message" then |
556 message_stanza_handler(origin, stanza); | 556 message_stanza_handler(origin, stanza); |
557 end | 557 end |
558 end | 558 end |
580 end | 580 end |
581 end); | 581 end); |
582 --]] | 582 --]] |
583 | 583 |
584 -- Component registration hooks: these hook in with the Prosody component | 584 -- Component registration hooks: these hook in with the Prosody component |
585 -- manager | 585 -- manager |
586 module:hook("iq/bare", sms_event_handler); | 586 module:hook("iq/bare", sms_event_handler); |
587 module:hook("message/bare", sms_event_handler); | 587 module:hook("message/bare", sms_event_handler); |
588 module:hook("presence/bare", sms_event_handler); | 588 module:hook("presence/bare", sms_event_handler); |
589 module:hook("iq/full", sms_event_handler); | 589 module:hook("iq/full", sms_event_handler); |
590 module:hook("message/full", sms_event_handler); | 590 module:hook("message/full", sms_event_handler); |