GithubHelp home page GithubHelp logo

generall / telegram-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shouya/telegram-bot

0.0 2.0 0.0 103 KB

Yet another client for Telegram's Bot API

Home Page: https://core.telegram.org/bots/api

License: MIT License

Ruby 100.00%

telegram-bot's Introduction

TelegramBotRuby

telegram api doc

Installation

Add this line to your application's Gemfile:

gem 'telegram_bot_ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install telegram_bot_ruby

Usage

Set up client

require 'telegram_bot'

bot = TelegramBot.new(token: <token>)

bot.listen(method: :webhook, url: '/meow/meow')  # not implemented yet
# or
bot.listen(method: :poll, interval: 1)

Set up update listeners

bot.on :command, 'ping' do  # /ping
  reply 'pong'
end

bot.on :command, 'plus' do |num1, num2|  # /plus 1 2
  reply (num1.to_i + num2.to_i).to_s
end

bot.on :text 'ping' do     # plain 'ping'
  send_message 'pong'
end

# with block: false, message will keep passing through other listeners
bot.on :text, /(\d+)\+(\d+)\=\?/, block: false do |n1, n2|
  send_chat_action :typing
  send_message (n1.to_i + n2.to_i).to_s
end

# a simple history logger
bot.on :anything do |msg|
  Database.save [msg.from.username, msg.text] if !msg.text.empty?
end

Start && Stop

# register service at telegram or start long polling
bot.start!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/shouya/telegram-bot.

License

The gem is available as open source under the terms of the MIT License.

telegram-bot's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.