File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
examples/webhook_examples Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import telebot
2+ import os
3+ from flask import Flask , request
4+
5+ bot = telebot .TeleBot ('token' )
6+
7+ server = Flask (__name__ )
8+
9+ @bot .message_handler (commands = ['start' ])
10+ def start (message ):
11+ bot .reply_to (message , 'Hello, ' + message .from_user .first_name )
12+
13+ @bot .message_handler (func = lambda message : True , content_types = ['text' ])
14+ def echo_message (message ):
15+ bot .reply_to (message , message .text )
16+
17+ @server .route ("/bot" , methods = ['POST' ])
18+ def getMessage ():
19+ bot .process_new_messages (
20+ [telebot .types .Update .de_json (request .stream .read ().decode ("utf-8" )).message
21+ ])
22+ return "!" , 200
23+
24+ @server .route ("/" )
25+ def webhook ():
26+ bot .remove_webhook ()
27+ bot .set_webhook (url = "https://herokuProject_url/bot" )
28+ return "!" , 200
29+
30+ server .run (host = "0.0.0.0" , port = os .environ .get ('PORT' , 5000 ))
31+
32+ server = Flask (__name__ )
You can’t perform that action at this time.
0 commit comments