forked from atipugin/telegram-bot-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6f6235
Showing
26 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Gemfile.lock | ||
|
||
.bundle/ | ||
vendor/bundle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
inherit_from: .rubocop_todo.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This configuration was generated by `rubocop --auto-gen-config` | ||
# on 2015-06-27 20:51:46 +0300 using RuboCop version 0.32.1. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 15 | ||
Style/Documentation: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# telegram-bot | ||
|
||
Ruby wrapper for [Telegram's Bot API](https://core.telegram.org/bots/api). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'bundler/gem_tasks' | ||
require 'bundler/setup' | ||
require 'rubocop/rake_task' | ||
|
||
RuboCop::RakeTask.new(:rubocop) do |task| | ||
task.fail_on_error = false | ||
task.options = %w(--force-exclusion) | ||
task.patterns = %w(lib/**/*.rb) | ||
end | ||
|
||
task default: :rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
require 'bundler/setup' | ||
require 'telegram/bot' | ||
|
||
require 'pry' | ||
Pry.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'httparty' | ||
require 'persistent_httparty' | ||
require 'virtus' | ||
|
||
require 'telegram/bot/api' | ||
require 'telegram/bot/types' | ||
require 'telegram/bot/runner' | ||
require 'telegram/bot/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Telegram | ||
module Bot | ||
class Api | ||
include HTTParty | ||
|
||
ENDPOINTS = %w( | ||
getMe sendMessage forwardMessage sendPhoto sendAudio sendDocument | ||
sendSticker sendVideo sendLocation sendChatAction getUserProfilePhotos | ||
getUpdates setWebhook | ||
).freeze | ||
|
||
attr_reader :token | ||
|
||
base_uri 'https://api.telegram.org' | ||
persistent_connection_adapter | ||
|
||
def initialize(token) | ||
@token = token | ||
end | ||
|
||
def method_missing(method_name, *args, &block) | ||
ENDPOINTS.include?(method_name.to_s) ? call(method_name, *args) : super | ||
end | ||
|
||
def call(endpoint, params = {}) | ||
self.class.get("/bot#{token}/#{endpoint}", query: params).to_h | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Telegram | ||
module Bot | ||
class Runner | ||
attr_reader :api, :offset | ||
|
||
def self.run(*args, &block) | ||
new(*args).run(&block) | ||
end | ||
|
||
def initialize(token) | ||
@api = Api.new(token) | ||
@offset = 0 | ||
end | ||
|
||
def run | ||
yield self | ||
end | ||
|
||
def listen | ||
loop do | ||
response = api.getUpdates(offset: offset) | ||
next unless response['ok'] | ||
|
||
response['result'].each do |data| | ||
update = Types::Update.new(data) | ||
@offset = update.update_id.next | ||
yield update.message | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'telegram/bot/types/base' | ||
require 'telegram/bot/types/user' | ||
require 'telegram/bot/types/group_chat' | ||
require 'telegram/bot/types/audio' | ||
require 'telegram/bot/types/photo_size' | ||
require 'telegram/bot/types/document' | ||
require 'telegram/bot/types/sticker' | ||
require 'telegram/bot/types/video' | ||
require 'telegram/bot/types/contact' | ||
require 'telegram/bot/types/location' | ||
require 'telegram/bot/types/message' | ||
require 'telegram/bot/types/update' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Audio < Base | ||
attribute :file_id, String | ||
attribute :duration, Integer | ||
attribute :mime_type, String | ||
attribute :file_size, Integer | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Base | ||
include Virtus.model | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Contact < Base | ||
attribute :phone_number, String | ||
attribute :first_name, String | ||
attribute :last_name, String | ||
attribute :user_id, String | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Document < Base | ||
attribute :file_id, String | ||
attribute :thumb, PhotoSize | ||
attribute :file_name, String | ||
attribute :mime_type, String | ||
attribute :file_size, Integer | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class GroupChat < Base | ||
attribute :id, Integer | ||
attribute :title, String | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Location < Base | ||
attribute :longitude, Float | ||
attribute :latitude, Float | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Message < Base | ||
attr_accessor :chat | ||
|
||
attribute :message_id, Integer | ||
attribute :from, User | ||
attribute :date, Integer | ||
attribute :forward_from, User | ||
attribute :forward_date, Integer | ||
attribute :reply_to_message, Message | ||
attribute :text, String | ||
attribute :audio, Audio | ||
attribute :document, Document | ||
attribute :photo, Array[PhotoSize] | ||
attribute :sticker, Sticker | ||
attribute :video, Video | ||
attribute :contact, Contact | ||
attribute :location, Location | ||
attribute :new_chat_participant, User | ||
attribute :left_chat_participant, User | ||
attribute :new_chat_title, String | ||
attribute :new_chat_photo, Array[PhotoSize] | ||
attribute :delete_chat_photo, Boolean | ||
attribute :group_chat_created, Boolean | ||
|
||
def chat=(value) | ||
@chat = | ||
if value.key?('username') | ||
User.new(value) | ||
elsif value.key?('title') | ||
GroupChat.new(value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class PhotoSize < Base | ||
attribute :file_id, String | ||
attribute :width, Integer | ||
attribute :height, Integer | ||
attribute :file_size, Integer | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Sticker < Base | ||
attribute :file_id, String | ||
attribute :width, Integer | ||
attribute :height, Integer | ||
attribute :thumb, PhotoSize | ||
attribute :file_size, Integer | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Update < Base | ||
attribute :update_id, Integer | ||
attribute :message, Message | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class User < Base | ||
attribute :id, Integer | ||
attribute :first_name, String | ||
attribute :last_name, String | ||
attribute :username, String | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Telegram | ||
module Bot | ||
module Types | ||
class Video < Base | ||
attribute :file_id, String | ||
attribute :width, Integer | ||
attribute :height, Integer | ||
attribute :duration, Integer | ||
attribute :thumb, PhotoSize | ||
attribute :mime_type, String | ||
attribute :file_size, Integer | ||
attribute :caption, String | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Telegram | ||
module Bot | ||
VERSION = '0.1.0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
require 'telegram/bot/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'telegram-bot' | ||
spec.version = Telegram::Bot::VERSION | ||
spec.authors = ['Alexander Tipugin'] | ||
spec.email = ['[email protected]'] | ||
|
||
spec.summary = "Ruby wrapper for Telegram's Bot API" | ||
spec.homepage = 'https://github.com/atipugin/telegram-bot' | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } | ||
spec.bindir = 'exe' | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'httparty' | ||
spec.add_dependency 'persistent_httparty' | ||
spec.add_dependency 'virtus' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.9' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'pry' | ||
spec.add_development_dependency 'rubocop' | ||
end |