Skip to content

gdwrd/mruby-tbot

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

mruby-tbot

Build Status License MRuby Version

MRuby wrapper for Telegram's Bot API.

Install by mrbgems

  • add conf.gem line to build_config.rb
MRuby::Build.new do |conf|
  conf.gem :mgem => 'mruby-tbot'
end

Example

bot = TBot::Bot.new(telegram_token)

bot.get_bot_data    # return bot info

bot.response        # last request response

bot.messages do |msg|
  msg.class # => Hash

  # custom keyboard for Reply Markup
  keyboard = [
    ['Hello!', 'Bye!'],
    ['Exit', 'Docs']
  ] #=> Array

  # ReplyKeyboardMarkup
  reply_markup = {
    keyboard: keyboard,
    resize_keyboard: true,
    one_time_keyboard: true,
    selective: true
  }

  # Send Message
  bot.message(msg, { text: 'text message', reply_markup: reply_markup }) # => Hash response
end

Send Document

bot.document(message, { document: File.open('document.doc','rb') })

Send Photo

bot.photo(message, { photo: File.open('photo.jpeg','rb') })

Send Sticker

bot.sticker(message, { sticker: File.open('sticker.png','rb') })

Send Audio

bot.audio(message, { sticker: File.open('audio.mp3','rb') })

Send Voice

bot.voice(message, { sticker: File.open('voice.mp3','rb') })

Send location

bot.location(message, { latitude: 54.44, longitude: 80.0 })

Send Venue

bot.venue(message, { latitude: 50.00, longitude: 80.0, title: "Name", address: "Address" })

Send Contact

bot.contact(message, { phone_number: "+123456789010", first_name: "Name", last_name: "Test" })

Send Chat Action

bot.chat_action(message, { action: "typing" })

License

Under the MIT License:

  • see LICENSE file