Skip to content

Commit

Permalink
Only check messages for selected Twilio number
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingDiver committed Jun 21, 2021
1 parent 141c267 commit f53719e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Twilio.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ def checkMessages(self, twilioDevice):

deleteMsgs = twilioDevice.pluginProps.get('delete', False)
lastMessageStamp = datetime.strptime(self.pluginPrefs.get(u"lastMessageStamp", "2000-01-01 00:00:00"), '%Y-%m-%d %H:%M:%S')
self.logger.debug(u"checkMessages: checking {}, lastMessageStamp {}".format(twilioDevice.name, lastMessageStamp))
messageStamp = lastMessageStamp

try:
for message in self.twilioClient.messages.list():
for message in self.twilioClient.messages.list(to=twilioDevice.address):
self.logger.debug(u"checkMessages: Message from %s, to: %s, direction: %s, date_sent: '%s'" % (message.from_, message.to, message.direction, message.date_sent))
if message.date_sent and (message.date_sent.replace(tzinfo=pytz.UTC) > lastMessageStamp.replace(tzinfo=pytz.UTC)):
messageStamp = message.date_sent
Expand Down Expand Up @@ -446,7 +447,7 @@ def checkMessages(self, twilioDevice):

def checkAllMessages(self):
for dev in indigo.devices.iter("self"):
if (dev.deviceTypeId == "twilioNumber"):
if (dev.deviceTypeId == "twilioNumber") and dev.enabled:
self.checkMessages(dev)

def updateWebhooks(self):
Expand Down

0 comments on commit f53719e

Please sign in to comment.