Ejemplo n.º 1
0
def send_message(article: Article) -> None:
    users = TelegramUser.objects.only("user_id")
    bot = Bot(token=os.getenv('TELEGRAM_BOT'))
    link = 'http://127.0.0.1:8000' + article.get_absolute_url()

    for user in users:
        message = f'<b>{article.title}</b>\n{article.short_text} \n<a href="{link}">Read more</a>'

        bot.send_message(chat_id=user.user_id, text=message, parse_mode='HTML')