Post by account_disabled on Jan 23, 2024 4:57:43 GMT
We are given pictures and descriptions of products and need to make a catalog from them. This catalog will be used by a telegram bot that wanders through the catalogs and offers the user products, displaying pictures and options for navigating through the catalog. Implementation. We will put pictures and text files into directories. We will have a common directory in which each bot will have its own, named after it. The bot's directory will have many subdirectories, each of which will have a picture of the product and a message.txt text file with instructions for the bot to create a message when it gets into this directory. This file will contain the contents of each bot message formatted as an xml doEXPLICITent. For example. The message tag specifies the bot's text message. Buttons will be created from button tags, on which the bot will jump to other directories specified in their value attribute. To work we need the following libraries:How to register a bot and get a secret key (token).
Need to find a contactBotFather. Write a command/newbot Choose a unique name, after which you will be sent a message of this type. Done! Congratulations on your new bot. You will find it at t.me/zdimon77_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: 829228816:AAGSjgoh0hfj-fwyMBo4UlGvGxHtnp6Z_сs Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: core.telegram.org/bots/api Let's start writing the bot in a filerun.py. It will be launched with one parameter - the bot's name. First, let's import everything we need. import sys import os from telegram.ext import Updater from telegram.ext import CommandHand B2B Email List ler, CallbackContext, CallbackQueryHandler from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram import Bot from bs4 import BeautifulSoup from install import DATA_DIR Let's take the bot's name from the first command line argument, and if it's not there, we'll report it and fall out of the program. try: botname = sys.argv[1] except:
скаю бота %s" % botname) bot_path = '%s/%s' % (DATA_DIR,botname) print("Читаю настройки из %s" % bot_path key = f.read() f.close() print("Ключ: %s" % key) bot = Bot(token=key) Let's define the start function, which will be triggered when the user clicks on the Start button in the Telergam program. def start(update: Updater, context: CallbackContext): print("Start command!") This function will be passed two objects update and context. We will use update to get information about the arriving user. For example, you can get his login and room ID like this: username = update.message.from_user['username'] room_id = update.message.chat_id We will use this ID further to send messages to the user's channel. In order to bind this function to the event handler for clicking on the “Start” button, you need to create a handler object of the CommandHandler class and “feed” our start function to it. start_handler = CommandHandler('start', start) The first parameter is the name of the command, in this case it is a reserved name, but it can be arbitrary and defined by the programmer.
Need to find a contactBotFather. Write a command/newbot Choose a unique name, after which you will be sent a message of this type. Done! Congratulations on your new bot. You will find it at t.me/zdimon77_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. Use this token to access the HTTP API: 829228816:AAGSjgoh0hfj-fwyMBo4UlGvGxHtnp6Z_сs Keep your token secure and store it safely, it can be used by anyone to control your bot. For a description of the Bot API, see this page: core.telegram.org/bots/api Let's start writing the bot in a filerun.py. It will be launched with one parameter - the bot's name. First, let's import everything we need. import sys import os from telegram.ext import Updater from telegram.ext import CommandHand B2B Email List ler, CallbackContext, CallbackQueryHandler from telegram import InlineKeyboardButton, InlineKeyboardMarkup from telegram import Bot from bs4 import BeautifulSoup from install import DATA_DIR Let's take the bot's name from the first command line argument, and if it's not there, we'll report it and fall out of the program. try: botname = sys.argv[1] except:
скаю бота %s" % botname) bot_path = '%s/%s' % (DATA_DIR,botname) print("Читаю настройки из %s" % bot_path key = f.read() f.close() print("Ключ: %s" % key) bot = Bot(token=key) Let's define the start function, which will be triggered when the user clicks on the Start button in the Telergam program. def start(update: Updater, context: CallbackContext): print("Start command!") This function will be passed two objects update and context. We will use update to get information about the arriving user. For example, you can get his login and room ID like this: username = update.message.from_user['username'] room_id = update.message.chat_id We will use this ID further to send messages to the user's channel. In order to bind this function to the event handler for clicking on the “Start” button, you need to create a handler object of the CommandHandler class and “feed” our start function to it. start_handler = CommandHandler('start', start) The first parameter is the name of the command, in this case it is a reserved name, but it can be arbitrary and defined by the programmer.