1
ユーザーが「開始」を押したときに表示されるKeyboardButtonを持つ簡単な電報ボットを持っています。ユーザがKeyboardButtonを押すと、ウィンドウが現れ、そのウィンドウ内にユーザは「電話番号の共有」ボタンを押す。この電話番号を取得する必要がありますが、応答の「連絡先」オブジェクトは空です。私が使用するモジュール - pyTelegramBotApi。KeyboardButtonでユーザーの電話番号を取得できない
import telebot
from telebot import types
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['start'])
def register(message):
keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=True)
reg_button = types.KeyboardButton(text="Share your phone number", request_contact=True)
keyboard.add(reg_button)
response = bot.send_message(message.chat.id,
"You should share your phone number",
reply_markup=keyboard)
print(response.contact) # response.contact = None here
if __name__ == '__main__':
bot.polling(none_stop=True)
これは、ユーザーから電話番号を取得する正しい方法ですか?いいえ、どうすれば入手できますか?
申し訳ありませんが、私のせい:
あなたはあなたの
get_contact
関数を定義する必要があります。私は間違ったモジュールをタグに追加しました。 python-telegram-botではなく、pyTelegramBotAPIを使用しています。 –