Пример #1
0
 def recieveMessage(self, body, sender, date):
   h.addMessageToDB(body, Twilio.Number, sender, 'inbound', date)
   jsonMessage = json.loads(body)
   app_id = jsonMessage["app_id"]
   api_class = mapper[app_id]()
   method = jsonMessage["method"]
   assert hasattr(api_class, method), "API Class {} does not have method {}".format(api_class, method)
   params = jsonMessage["params"]
   respMessage = getattr(api_class, method)(*params)
   return self.sendMessage(str(respMessage), sender, app_id)
Пример #2
0
 def sendMessage(self, body, to_number, app_id):
   # "00010|012|004|1|{app='weather'}"
   # "message_id|total|fragment_id|app_id|{app='weather'}"
   unique_id = h.addMessageToDB(body, to_number, Twilio.Number, 'outboud', time.strftime("%H:%M:%S"))
   partitions = textwrap.wrap(body, MAX_CONTENT_SIZE)
   for idx, partition in enumerate(partitions):
     partition = cleanString(partition)
     uid = fix_number(unique_id, 5)
     frag_len = fix_number(len(partitions), 2)
     frag_id = fix_number(idx + 1, 2)
     app_id = fix_number(app_id, 1)
     body = "{}|{}|{}|{}|{}".format(uid, frag_len, frag_id, app_id, partition)
     message = self.client.messages.create(body=body,
       to=to_number,                # Replace with your phone number
       from_=Twilio.Number)  # Replace with your Twilio number
   return message.sid