Skip to content

Commit

Permalink
Added bot_login.py example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akhmetov committed Apr 5, 2019
1 parent 79e7885 commit 56f4f26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

- Fixed problem with randomly raised "Database encryption key is needed" errors during login process. (#12)
- Fixed `stop` method execution. (#8)
- Added ``examples/bot_login.py`` example.

[0.8.0] - 2019-03-17

Expand Down
28 changes: 28 additions & 0 deletions examples/bot_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import argparse

from telegram.client import Telegram


def bot_get_me(api_id, api_hash, token):
tg = Telegram(
api_id=api_id,
api_hash=api_hash,
bot_token=token,
database_encryption_key='changeme1234',
)
# you must call login method before others
tg.login()

result = tg.get_me()
result.wait()
print(result.update)
tg.stop()


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('api_id', help='API id') # https://my.telegram.org/apps
parser.add_argument('api_hash', help='API hash')
parser.add_argument('token', help='Bot token')
args = parser.parse_args()
bot_get_me(args.api_id, args.api_hash, args.token)

0 comments on commit 56f4f26

Please sign in to comment.