require 'telegram/bot' token = 'YOUR_TELEGRAM_BOT_API_TOKEN' Telegram::Bot::Client.run(token) do |bot| bot.listen do |message| case message.text when '/start' bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}") end end end
gem install telegram-bot-ruby
gem 'telegram-bot-ruby'
bundle
require 'telegram/bot' token = '118997426:AAFVFtYa15Z7ckyDUIHb578NazgepL4kmU8' Telegram::Bot::Client.run(token) do |bot| bot.listen do |message| case message.text when '/start' bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}") end end end
ruby start_bot.rb
require 'telegram/bot' token = '<>' Telegram::Bot::Client.run(token) { |bot| bot.listen { |message| bot.api.sendMessage(chat_id: message.chat.id, text: 'Hi!') if message.text == '/start' } }
from twx.botapi import TelegramBot token = '<>' while True: [lambda update: TelegramBot(token).send_message(update.message.chat.id, 'test message body') if update.message.text.startswith('/start') else None for update in TelegramBot(token).get_updates().wait()]
Source: https://habr.com/ru/post/264707/
All Articles