[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.dp = self._create_dispatcher()
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())
except CancelledError:
logger.debug(f'Bot {self.telegram_model.hood.name} received Cancellation.')

View file

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