Permalink
Browse files

MesageMedia - Improved status logging

  • Loading branch information...
mludvig committed Feb 16, 2012
1 parent 9a8557c commit f17c1d93cdd08e88c130fd18c9a217a4fecfa464
Showing with 10 additions and 4 deletions.
  1. +10 −4 Sms/Engines/MessageMedia.py
@@ -6,6 +6,7 @@
from Sms.Exceptions import SmsError
import GenericSoap
+import random
from suds.client import Client
class SmsDriver(GenericSoap.SmsDriver):
@@ -19,23 +20,28 @@ def send(self, message, recipient):
auth.userId = self.options['username']
auth.password = self.options['password']
+ # Message ID
+ message_id = random.randint(100000000, 999999999)
+
# Message Type
message_t = client.factory.create("MessageType")
message_t.content = message
message_t.deliveryReport = True
message_t.recipients.recipient.append(client.factory.create("RecipientType"))
message_t.recipients.recipient[-1].value = recipient
- # message_t.recipients.recipient[-1]._uid = recipient + rand()
+ message_t.recipients.recipient[-1]._uid = message_id
# Container for multiple messages
send_messages_t = client.factory.create("SendMessagesBodyType")
send_messages_t.messages.message.append(message_t)
- print send_messages_t
-
# Send it out
ret = client.service.sendMessages(auth, send_messages_t)
- print ret
+ if ret._sent > 0:
+ info("SMS(MessageMedia) sent to %s with ID: %s" % (recipient, message_id))
+ return message_id
+ if ret._failed > 0:
+ warning("SMS(MessageMedia) failed to %s: %s" % (recipient, ret.errors.error[0]._code))
# vim:et:ts=4:sts=4:ai

0 comments on commit f17c1d9

Please sign in to comment.