From 6979c88d145072bc9112328c006119b19315e348 Mon Sep 17 00:00:00 2001 From: David Todd Date: Sun, 19 Jan 2020 17:45:21 -0600 Subject: [PATCH] setup bot connection to telegram --- api/db/telethon_db.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/db/telethon_db.py b/api/db/telethon_db.py index 1bb0cf5..30d61d3 100644 --- a/api/db/telethon_db.py +++ b/api/db/telethon_db.py @@ -10,6 +10,8 @@ import datetime import sqlite3 import uuid +import os +from telethon.sync import TelegramClient from .db import Database class TelethonDatabase(Database): @@ -27,6 +29,17 @@ class TelethonDatabase(Database): """ super(TelethonDatabase, self).__init__(database) + # Load in the API tokens required for a bot + api_id = os.environ.get('telethon_api_id', False) + api_hash = os.environ.get('telethon_api_hash', False) + api_token = os.environ.get('telethon_token', False) + + # Create an instance of the Telethon bot + if api_id and api_hash and api_token: + self.bot = TelegramClient('bot', api_id, api_hash).start(bot_token=api_token) + else: + self.bot = False + # Automatically create the table if it doesn't # already exist in the selected database self._create_table()