Socket
Book a DemoInstallSign in
Socket

telegram-support-bot

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegram-support-bot

0.1.06
bundlerRubygems
Version published
Maintainers
1
Created
Source

TelegramSupportBot

Introduction

TelegramSupportBot is a Ruby gem designed to enhance customer support through Telegram, allowing for the management of queries directly from a designated chat while ensuring privacy and confidentiality.

Features

  • Forward messages between users and a support chat
  • Supports various message types (text, images, videos, documents, audio, stickers)
  • Auto-away messages for off-hours
  • Simple configuration and deployment

Installation

Add to your Gemfile:

gem 'telegram-support-bot'

Usage

Creating and Configuring Your Bot

  • Create Your Bot via BotFather on Telegram to get your bot token.
  • Deploy Your Application and set up a controller action for webhook callbacks, directing them to TelegramSupportBot.process_update.
  • Set the Webhook URL using the Telegram Bot API to your controller action.

Setting Up Your Telegram Bot

  • Add Your Bot to a Support Chat and obtain the support_chat_id by sending the /start command to the bot inside the support chat.
  • Configure Your Bot in your Ruby application with the token and support_chat_id, and set a welcome message.
TelegramSupportBot.configure do |config|
  config.adapter         = :telegram_bot
  config.adapter_options = { token: 'YOUR_TELEGRAM_BOT_TOKEN' }
  config.support_chat_id = 'YOUR_SUPPORT_CHAT_ID'
  config.welcome_message = 'Hi! How can we help you?'
end
  • Interact with Users: Messages to your bot will be forwarded to the support chat, and replies in the chat will be sent back to the users.

Adapters

TelegramSupportBot supports integration through adapters. Currently, telegram-bot and telegram-bot-ruby are supported.

Configuration is pretty much the same for both gems:

TelegramSupportBot.configure do |config|
  config.adapter         = :telegram_bot
  config.adapter_options = { token: 'YOUR_TELEGRAM_BOT_TOKEN' }
end
TelegramSupportBot.configure do |config|
  config.adapter         = :telegram_bot_ruby
  config.adapter_options = { token: 'YOUR_TELEGRAM_BOT_TOKEN' }
end

Examples

Basically, just make sure you call TelegramSupportBot.process_update somewhere in you workflow cycle and pass it a parsed json update received from Telegram servers.

Using telegram-bot Gem with a Webhook Controller

If you're using the telegram-bot gem, set up a Rails controller to handle incoming webhook requests. Here's an example of how you might implement such a controller:


class TelegramWebhooksController < ApplicationController

  def webhook
    update = JSON.parse(request.body.read)
    TelegramSupportBot.process_update(update)
    head :ok
  end
end

Make sure to configure your routes to direct webhook callbacks to this controller action.

Using telegram-bot-ruby Gem with bot.listen

For those utilizing telegram-bot-ruby, you can set up a simple listener loop to process incoming messages. This approach is more suited for polling rather than webhooks: require 'telegram/bot'

token = 'YOUR_TELEGRAM_BOT_TOKEN'

Telegram::Bot::Client.run(token) do |bot|
  bot.listen do |message|
    TelegramSupportBot.process_update(update.to_h)
  end
end

Custom Adapter Implementation

Implement custom adapters by inheriting from TelegramSupportBot::Adapter::Base and defining message sending and forwarding methods.

Development

  • Run bin/setup to install dependencies.
  • Use rake spec for tests and bin/console for an interactive prompt.
  • To install locally, use bundle exec rake install.
  • For releases, update version.rb, and run bundle exec rake release.

Contributing

Contributions are welcome via GitHub, adhering to the code of conduct.

License

Available under the MIT License.

Code of Conduct

Follow the project's code of conduct.

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.