[英]Ruby Telegram Bot
我想讓 Telegram Bout 從 Telegram 中撤回自定義信息。
when "/invite (xyz)"
bot.api.send_message(chat_id: message.chat.id, text: "Inviting (xyz)")
機器人應該將(xyz)撤回到自定義消息。 另一個想法是,我怎樣才能讓 ruby 將我的自定義名稱粘貼到文本文件中,並使用命令行“/invite (xyz)”<--- 到文本文件中。 所以如果我在電報上這樣做:/invite Rob
Telegram 應該寫給我“Inviting Rob”並將我打印到文本文件“/invite Rob”中
有什么方法可以取出自定義(xyz)字並讀出並在代碼中使用它?
你可以做類似的事情
if text_field.start_with? '/invite '
bot.api.send_message(chat_id: message.chat.id, text: "Inviting #{text_field.sub('/invite ',''}"
案例留言
當 Telegram::Bot::Types::Message
if message.text.start_with?('/start')
...
elsif message.text.start_with?('/help')
...
else
...
end
結尾
您可以使用正則表達式:
case str
when /\/invite (.*)/
bot.api.send_message(chat_id: message.chat.id, text: "Inviting #{Regexp.last_match[1]}")
File.open('your_file.txt', 'a') { |f| f.puts(Regexp.last_match) }
when /\/greet (.*)/
# ...
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.