-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_webhook.py
executable file
·44 lines (33 loc) · 1.04 KB
/
init_webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
import os
from twx.botapi import InputFileInfo, InputFile
from app import application
from app import bot
def init_heroku_logging():
import logging
stream_handler = logging.StreamHandler()
application.logger.addHandler(stream_handler)
application.logger.setLevel(logging.DEBUG)
def get_certificate():
certificate_path = 'app/ssl-certificate.herokuapp-com.pem'
fp = open(certificate_path, 'rb')
file_info = InputFileInfo(
file_name=certificate_path,
fp=fp,
mime_type='text/plain')
return InputFile('certificate', file_info)
def init_bot(telegram_bot):
telegram_bot.update_bot_info().wait()
print('Starting bot %s' % telegram_bot.username)
certificate = get_certificate()
telegram_bot.set_webhook(
url='https://morning-chamber-85976.herokuapp.com/incoming',
certificate=certificate,
).wait()
print('Webhook configured')
if os.environ.get('HEROKU') is not None:
init_heroku_logging()
try:
init_bot(bot)
except Exception as e:
print(e)