V
V
vadimeasy2021-10-06 08:26:48
Python
vadimeasy, 2021-10-06 08:26:48

Write function with variable from user for Telegram bot in Python?

Good afternoon! I've been fighting over the bot in the telegarm for a week now. I want to make a function that writes the user's message to a variable and issues it with a message, an already set variable + a variable that the user sent. So far implemented the function on the echo bot

from typing import Text
import telebot
from telebot import types
import time

bot = telebot.TeleBot('')

link = "http://api.whatsapp.com/send/?phone="




@bot.message_handler(commands=['start'])
def start(message):
    bot.send_message(message.chat.id, 'Напиши номер телефона, а я пришлю тебе ссылку в формате:')
    bot.send_message(message.chat.id, link + 'НОМЕР')
@bot.message_handler(content_types=['text'])
def txt(message):
    bot.send_message(message.chat.id, link + message.text)



bot.polling()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Python Newbie, 2021-10-06
@vadimeasy

import telebot

bot = telebot.TeleBot('TOKEN')

def number(message):
    bot.send_message(message.chat.id, f'Вот твоя ссылка: http://api.whatsapp.com/send/?phone={message.text}')

@bot.message_handler(commands=['start'])
def welcom(message):
    bot.send_message(message.chat.id, 'Отправь номер телефона')
    bot.register_next_step_handler(message, number)

bot.polling()

bot.register_next_step_handler(message, number)moves to another function

S
soremix, 2021-10-06
@SoreMix

You can just open the examples
https://github.com/eternnoir/pyTelegramBotAPI/blob...
Or search the site, there is a question about the step handler and the answer is stable once a week

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question