Last active
August 15, 2021 09:19
-
-
Save RubyOcelot/654d6ba5060e9b23c20d6fc49e62eb53 to your computer and use it in GitHub Desktop.
telegram bot get chat id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telegram.ext import Updater, MessageHandler, CallbackContext | |
from telegram.ext.filters import Filters | |
import requests | |
#require python-telegram-bot requests(optional) | |
def show_id(update,context): | |
bot=context.bot | |
chat_id = update.message.chat_id | |
print(chat_id) | |
if(chat_id<0): | |
print("from group") | |
bot.send_message(chat_id=chat_id,text="group: "+str(chat_id)) | |
else: | |
print("from user") | |
bot.send_message(chat_id=chat_id,text="chat: "+str(chat_id)) | |
def main(): | |
token_file=open("secret.txt", mode='r') | |
my_token= token_file.readline()[:-1] | |
#print(my_token) | |
#str1="https://api.telegram.org/bot{token}/getUpdates".format(token=my_token) | |
#print(str1) | |
#print(requests.get(str1)) | |
with open("proxy.txt", mode='r') as f: | |
my_proxy=f.readline()[:-1] | |
REQUEST_KWARGS={ | |
'proxy_url': my_proxy, | |
} | |
updater = Updater(my_token, use_context=True, request_kwargs=REQUEST_KWARGS) | |
dp = updater.dispatcher | |
dp.add_handler(MessageHandler(filters=Filters.all,callback=show_id)) | |
updater.start_polling() | |
updater.idle() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment