[telegram] Add username to telegram bots

This commit is contained in:
Cathy Hu 2020-08-31 14:08:53 +02:00
parent a7f0898fd7
commit 5e9a947284
2 changed files with 4 additions and 0 deletions

View file

@ -32,6 +32,9 @@ class TelegramBot(Censor):
self.bot = Bot(token=self.telegram_model.api_token) self.bot = Bot(token=self.telegram_model.api_token)
self.dp = self._create_dispatcher() self.dp = self._create_dispatcher()
logger.debug(f'Bot {self.telegram_model.hood.name} starting.') logger.debug(f'Bot {self.telegram_model.hood.name} starting.')
user = await self.bot.get_me()
if user.username:
await self.telegram_model.update(username=user.username)
await gather(self.dp.start_polling(), self._push()) await gather(self.dp.start_polling(), self._push())
except CancelledError: except CancelledError:
logger.debug(f'Bot {self.telegram_model.hood.name} received Cancellation.') logger.debug(f'Bot {self.telegram_model.hood.name} received Cancellation.')

View file

@ -11,6 +11,7 @@ class Telegram(Model):
hood: ForeignKey(Hood) hood: ForeignKey(Hood)
api_token: Text(unique=True) api_token: Text(unique=True)
welcome_message: Text() welcome_message: Text()
username: Text(allow_null=True) = None
enabled: Boolean() = True enabled: Boolean() = True
class Mapping(Mapping): class Mapping(Mapping):