def process_incoming_chat_structure(self, u): # We can get messages for things that aren't actually messages, such as "you're invited to # a channel". if 'text' not in u['message']: return msgid = int(u['update_id']) if IncomingDirectMessage.objects.filter(provider_id=self.providerid, postid=msgid).exists(): # We've already seen this one return # Does it look like a token? If so, try to attach to this channel for m in re_token.findall(u['message']['text']): if self.process_token_match(m, u['message']): return # If the message has no sender, we're going to ignore it. This could for # exaple be an automatically forwarded message internally in Telegram. if 'username' not in u['message']['from'] or 'id' not in u['message']['from']: return # Else it's a regular message, so store it. msg = IncomingDirectMessage( provider_id=self.providerid, postid=msgid, time=datetime.fromtimestamp(int(u['message']['date']), tz=django.utils.timezone.utc), sender={ 'username': u['message']['from']['username'], 'userid': u['message']['from']['id'], }, txt=u['message']['text'], ) self.process_incoming_chat_message(msg) msg.save()
def process_incoming_dm(self, dm): for m in re_token.findall(dm.txt): try: reg = ConferenceRegistration.objects.get(regtoken=m) # We get the screen_name so we can be friendly to the user! And when we've # done that, we might as well cache it in the message info. dm.sender['name'] = self.get_user_screen_name(dm.sender['id']) reg.messaging_config = { 'twitterid': dm.sender['id'], 'screen_name': dm.sender['name'], } reg.save(update_fields=['messaging_config']) send_reg_direct_message( reg, 'Hello! This account is now configured to receive notifications for {}' .format(reg.conference)) dm.internallyprocessed = True self.send_read_receipt(dm.sender['id'], dm.postid) return except ConferenceRegistration.DoesNotExist: pass
def process_channel_post(self, p): if 'text' not in p: # This is some kind of channel post that is not text, so we just # ignore it. return # Does it look like a token? If so, try to attach this channel for m in re_token.findall(p['text']): if self.process_token_match(m, p): return
def process_incoming_chat_message(self, msg): # Does it look like a token? If so, try to attach! for m in re_token.findall(msg.txt): try: reg = ConferenceRegistration.objects.get(regtoken=m) # Matched reg, so set it up reg.messaging_config = msg.sender reg.save(update_fields=['messaging_config']) send_reg_direct_message(reg, 'Hello! This account is now configured to receive notifications for {}'.format(reg.conference)) msg.internallyprocessed = True return except ConferenceRegistration.DoesNotExist: pass
def process_incoming_dm(self, msg): for m in re_token.findall(msg['content']): try: reg = ConferenceRegistration.objects.get(regtoken=m) reg.messaging_config = { 'username': msg['account']['username'], } reg.save(update_fields=['messaging_config']) send_reg_direct_message( reg, 'Hello! This account is now configured to receive notifications for {}' .format(reg.conference)) except ConferenceRegistration.DoesNotExist: pass