[英]Telegram bot parse user's phone number using Ruby?
我正在嘗試讓Telegram機器人請求用戶提供他/她的號碼並對其進行操作。
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
case message
when Telegram::Bot::Types::CallbackQuery
when Telegram::Bot::Types::Message
case message.text
when '/help'
bot.api.send_message(
chat_id: message.chat.id,
text: 'Display help.'
)
end
if message.contact.phone_number == "1111111" #undefined method
bot.api.send_message(
chat_id: message.chat.id,
text: 'Number received.'
)
end
else
bot.api.send_message(
chat_id: message.chat.id,
text: 'Unknown command.'
)
end
end
end
我可以獲取Contact對象,但是如何訪問該對象的phone_number字段? 對Telegram機器人使用Ruby包裝器。
我通過在查詢其phone_number
字段之前將時間變量設置為Contact
對象來解決此問題。 不知道這是否是預期的交互,但它是否有效。
Telegram::Bot::Client.run(token) do |bot|
bot.listen do |message|
if sender = message.contact #Set a variable to the Contact object.
if sender.phone_number == "11111111"
bot.api.send_message(
chat_id: message.chat.id,
text: 'Phone number received.'
)
end
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.