D
D
Dmitry2022-04-06 19:14:16
JavaScript
Dmitry, 2022-04-06 19:14:16

How to make a person share a contact with a bot when clicking on a date?

how to make it so that when clicking on a date in the calendar, a person shares a contact With the bot and I receive a letter with the contacts of this user in the chat from the bot?

import telebot
from telebot import types
from telebot_calendar import Calendar, CallbackData, RUSSIAN_LANGUAGE
import datetime

bot = telebot.TeleBot(token)
calendar = Calendar(language=RUSSIAN_LANGUAGE)
calendar_1 = CallbackData('calendar_1', 'action', 'year', 'month', 'day')
now = datetime.datetime.now()

@bot.message_handler(commands=['start'])
def start(message):
    keyboard = types.ReplyKeyboardMarkup(True)
    button1 = types.KeyboardButton('ЗАПИСЬ НА СЪЕМКУ')
    keyboard.add(button1)
    bot.send_message(message.chat.id, 'Добро пожаловать, ' + message.from_user.first_name + '!', reply_markup=keyboard)

@bot.message_handler(content_types=['text'])
def call(message):
    #высвечиваем календарь при нажатии на кнопку ЗАПИСЬ НА СЪЕМКУ
    if message.text == 'ЗАПИСЬ НА СЪЕМКУ':
        bot.send_message(message.chat.id, 'Выберите дату', reply_markup=calendar.create_calendar(
            name=calendar_1.prefix,
            year=now.year,
            month=now.month)
            )

@bot.callback_query_handler(func=lambda call: call.data.startswith(calendar_1.prefix))
def callback_inline(call: types.CallbackQuery):
    name, action, year, month, day = call.data.split(calendar_1.sep)
    date = calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day)

    if action == 'DAY':
        bot.send_message(chat_id=call.from_user.id, text=f'Вы выбрали {date.strftime("%d.%m.%Y")}', reply_markup=types.ReplyKeyboardRemove())

    elif action == 'CANCEL':
        bot.send_message(chat_id=call.from_user.id, text='Отмена', reply_markup=types.ReplyKeyboardRemove())

where to write request_contact=True for the button?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abdula Magomedov, 2016-08-25
@game802

$(".tButton").click(function(){
        var showBlockClass = $(this).data("price"); 
        $(".bg3").fadeOut(0);
        $("."+showBlockClass).fadeIn(400);
});

S
soremix, 2022-04-06
@SoreMix

Send a replykeyboard to the user, pass a parameter to the button request_contact=True: Well, catch a message with a contact And then get the necessary fields https://core.telegram.org/bots/api#contact
types.KeyboardButton(request_contact=True)
@bot.message_handler(content_types=['contact'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question