# tg-bot > A simple Telegram Bot gem for Ruby on Rails # Usage 1. Setup your ENV - Use bash to set environment variable ```bash export telegram_bot_token='Your bot token' ``` - Use [figaro](https://github.com/laserlemon/figaro) gem to set environment variable ```yaml telegram_bot_token: Your bot token ``` 2. Add this gem to your `Gemfile` ```ruby gem 'tg-bot' ``` 3. Setup your Controller > e.g. my webhook is https://xxxxx/telegram ```ruby def telegram telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token']) end ``` 4. It has 3 ways to reply message ```ruby def telegram telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token']) # 1. reply text message telegram.send_message(text: 'enter what you want to reply') # 2. reply forward_message telegram.forward_message( chat_id: 'The chatroom you want to reply', from_chat_id: 'The chatroom you want to forward', message_id: 'The message you want to forward') # 3. reply photo by file or string telegram.send_photo(photo: "https://picsum.photos/200/300/?random=#{Random.new_seed}") end ``` # Methods ## [SetWebhook](https://github.com/VenseChang/telegram-bot-gem/blob/4b896317db7804cf8f5191974f5e942872300ba3/lib/tg-bot.rb#L25-L28) ```ruby def xxx Telegram::Bot::SetWebhook(url: url, token: ENV['telegram_bot_token']) end ``` ## [Send Message](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/send_message.rb) ```ruby def telegram telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token']) telegram.send_message( chat_id: 'chat_id', text: 'Enter you want to reply message text', parse_mode: 'HTML / Markdown ( Default Setting: HTML )', disable_web_page_preview: 'true / false', disable_notification: 'true / false', reply_to_message_id: 'message_id', reply_markup: 'inline keyboard, custom reply keyboard' ) end ``` ||type|memo| |---|---|---| |chat_id|Integer / String|**Required**
Default: chat_id from params| |text|String|**Required**
Enter reply Message| |parse_mode|String|**Optional**
Default: `HTML`
[HTML](https://core.telegram.org/bots/api#html-style) / [Markdown](https://core.telegram.org/bots/api#markdown-style)| |disable_web_page_preview|Boolean|**Optional**
true / false| |disable_notification|Boolean|**Optional**
true / false| |reply_to_message_id|Integer|**Optional**
Reply sb's message by message_id| ## [Forward Message](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/forward_message.rb) ```ruby def telegram telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token']) telegram.forward_message( chat_id: 'chat_id', from_chat_id: 'chat_id from forward message', message_id: 'message_id forward message', disable_notification: 'true / false' ) end ``` ||type|memo| |---|---|---| |chat_id|Integer / String|**Required**
Default: chat_id from params| |from_chat_id|Integer|**Required**
Chat Id from forward message| |message_id|String|**Required**
Message Id from forward message| |disable_notification|Boolean|**Optional**
true / false| ## [Send Photo](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/send_photo.rb) ```ruby def telegram telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token']) telegram.send_photo( chat_id: 'chat_id', photo: 'InputFile / File Id(String) / HTTP URL(String)', caption: 'Photo caption', parse_mode: 'HTML / Markdown ( Default Setting: HTML )', disable_notification: 'true / false', reply_to_message_id: 'message_id', reply_markup: 'inline keyboard, custom reply keyboard' ) end ``` ||type|memo| |---|---|---| |chat_id|Integer / String|**Required**
Default: chat_id from params| |photo|InputFile / String|**Required**
There's 3 ways to send photo:
1. Use `multipart/form-data` to upload new photo.
2. If the photo exist on Telegram servers, then pass `file_id` as String to send a photo.
3. Pass an HTTP URL as a String for Telegram to get a photo from the Internet.
[more](https://core.telegram.org/bots/api#sendphoto)| |caption|String|**Optional**
Photo caption (may also be used when resending photos by file_id)
***maximun characters : 1024***| |parse_mode|String|**Optional**
Default: `HTML`
[HTML](https://core.telegram.org/bots/api#html-style) / [Markdown](https://core.telegram.org/bots/api#markdown-style)| |disable_notification|Boolean|**Optional**
true / false| |reply_to_message_id|Integer|**Optional**
Reply sb's message by message_id| # Other If you have any questions or better advice for this gem, please use [Issue](https://github.com/VenseChang/telegram-bot-gem/issues/new) to tell me. Thanks for using this gem.