TelegemBot 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +17 -0
- data/README.markdown +0 -0
- data/Rakefile +34 -0
- data/lib/generators/tele_notify/migration/migration_generator.rb +35 -0
- data/lib/generators/tele_notify/migration/templates/active_record/migration.rb +19 -0
- data/lib/generators/tele_notify/migration/templates/active_record/tele_notify.rb +15 -0
- data/lib/tele_notify.rb +12 -0
- data/lib/tele_notify/engine.rb +3 -0
- data/lib/tele_notify/telegram_controller.rb +22 -0
- data/lib/tele_notify/telegram_user.rb +58 -0
- data/lib/tele_notify/version.rb +3 -0
- data/tele_notify.gemspec +25 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f2ca0f96a6f0e7abe2cff82906615b9abe828d7
|
4
|
+
data.tar.gz: 2728b040eb53d9d34fb547f4ceb3196f0580e15b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bd3efbda27585a6bdf2ff018ee4c46b183468a1a309c2a9c02e5db9e1f9ec5c06e5180d81c2f1c54887eb1c4ab8a36c9708a45f369b636d6920c6df0b99fc05
|
7
|
+
data.tar.gz: 8d6c29eabeff05ebfaab35482210fd1ddbb0a4fbfa2ada3c2bb2d60b628b8642fc14dfe4125224a3909790f0600a3fedc90e988f28e60623f92725a43bd4fd75
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in acts_as_votable.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
rails_version = ENV['RAILS_VERSION'] || 'default'
|
7
|
+
|
8
|
+
rails = case rails_version
|
9
|
+
when 'master'
|
10
|
+
{ :github => 'rails/rails'}
|
11
|
+
when 'default'
|
12
|
+
'~> 3.2.0'
|
13
|
+
else
|
14
|
+
"~> #{rails_version}"
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'rails', rails
|
data/README.markdown
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'TeleNotify'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module TeleNotify
|
4
|
+
class MigrationGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
desc "Generates migration for votable (votes table)"
|
8
|
+
|
9
|
+
def self.orm
|
10
|
+
Rails::Generators.options[:rails][:orm]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.orm_has_migration?
|
18
|
+
[:active_record].include? orm
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.next_migration_number(path)
|
22
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_migration_file
|
26
|
+
if self.class.orm_has_migration?
|
27
|
+
migration_template 'migration.rb', 'db/migrate/tele_notify_migration.rb'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_initializer
|
32
|
+
copy_file 'tele_notify.rb', 'config/initializers/tele_notify.rb'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TeleNotifyMigration < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :telegram_users do |t|
|
5
|
+
t.integer :telegram_id
|
6
|
+
t.string :first_name
|
7
|
+
t.string :username
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :telegram_users, :telegram_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :telegram_users
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#Set your home URL, so Telegram callbacks work
|
2
|
+
#For production, just use your URL (e.g. https://myapp.com)
|
3
|
+
#You MUST NOT include a trailing slash and it MUST be https!
|
4
|
+
#INVALID URLS: e.g. http://myapp.com or https://myapp.com/
|
5
|
+
TeleNotify::TelegramUser.configure_home_url("YOUR PRODUCTION URL")
|
6
|
+
|
7
|
+
#For development, download ngrok from https://ngrok.com/.
|
8
|
+
#Extract it and run "./ngrok http 3000"
|
9
|
+
#Then copy the URL you get from the console window.
|
10
|
+
#Remember to use the HTTPS URL!
|
11
|
+
TeleNotify::TelegramUser.configure_dev_url("YOUR NGROK DEVELOPMENT URL")
|
12
|
+
|
13
|
+
#Set your Telegram Bot API token here
|
14
|
+
#Don't have your token yet? Create your bot using https://telegram.me/botfather
|
15
|
+
TeleNotify::TelegramUser.configure_token("YOUR TOKEN")
|
data/lib/tele_notify.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module TeleNotify
|
2
|
+
module Controller
|
3
|
+
def webhook
|
4
|
+
if params[:message]
|
5
|
+
user = TelegramUser.create( { telegram_id: params[:message][:from][:id],
|
6
|
+
last_name: params[:message][:from][:last_name],
|
7
|
+
first_name: params[:message][:from][:first_name] } )
|
8
|
+
|
9
|
+
|
10
|
+
message = Message.create( { telegram_id: params[:message][:from][:id],
|
11
|
+
text: params[:message][:text],
|
12
|
+
last_name: params[:message][:from][:last_name],
|
13
|
+
first_name: params[:message][:from][:first_name] } )
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
render :nothing => true, :status => :ok
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module TeleNotify
|
4
|
+
class TelegramUser < ::ActiveRecord::Base
|
5
|
+
|
6
|
+
validates_presence_of :telegram_id
|
7
|
+
validates_uniqueness_of :telegram_id
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
@@next_update_id = 0
|
12
|
+
|
13
|
+
def self.configure_home_url(url)
|
14
|
+
@@home_url = url
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure_dev_url(url)
|
18
|
+
@@dev_url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.active_url
|
22
|
+
if Rails.env.production?
|
23
|
+
@@home_url
|
24
|
+
else
|
25
|
+
@@dev_url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def self.configure_token(token)
|
31
|
+
if token =~ /^[0-9]+:[\w-]+$/ #hacker proof
|
32
|
+
@@token = token
|
33
|
+
@@url = "https://api.telegram.org/bot" + token + "/"
|
34
|
+
@@callback_url = active_url + "/" + @@token
|
35
|
+
RestClient.post(@@url + "setWebhook", { url: @@callback_url })
|
36
|
+
else
|
37
|
+
raise "Invalid token! Please add a valid Telegram token in config/initializers/tele_notify.rb or see https://github.com/ppati000/tele_notify for further instructions."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.send_message_to_all(text)
|
42
|
+
success = true
|
43
|
+
TeleNotify::TelegramUser.all.each do |user|
|
44
|
+
success = false if !user.send_message(text)
|
45
|
+
end
|
46
|
+
success
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def send_message(text)
|
51
|
+
response = JSON.parse(RestClient.post(@@url + "sendMessage", chat_id: self.telegram_id, text: text), { symbolize_names: true })
|
52
|
+
response[:ok]
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/tele_notify.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tele_notify/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "TelegemBot"
|
7
|
+
s.version = TeleNotify::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Alessandro Varuzza"]
|
10
|
+
s.email = ["alessandrovaru@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/aless0117/telegramgem"
|
12
|
+
s.summary = "Rails gem to send and save messages via Telegram"
|
13
|
+
s.description = "Hi"
|
14
|
+
|
15
|
+
s.rubyforge_project = "acts_as_votable"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "rest-client", "~> 2.0.0.rc1"
|
23
|
+
|
24
|
+
s.add_development_dependency "sqlite3", '~> 1.3.9'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: TelegemBot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Varuzza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0.rc1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0.rc1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.9
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.9
|
41
|
+
description: Hi
|
42
|
+
email:
|
43
|
+
- alessandrovaru@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- lib/generators/tele_notify/migration/migration_generator.rb
|
53
|
+
- lib/generators/tele_notify/migration/templates/active_record/migration.rb
|
54
|
+
- lib/generators/tele_notify/migration/templates/active_record/tele_notify.rb
|
55
|
+
- lib/tele_notify.rb
|
56
|
+
- lib/tele_notify/engine.rb
|
57
|
+
- lib/tele_notify/telegram_controller.rb
|
58
|
+
- lib/tele_notify/telegram_user.rb
|
59
|
+
- lib/tele_notify/version.rb
|
60
|
+
- tele_notify.gemspec
|
61
|
+
homepage: https://github.com/aless0117/telegramgem
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project: acts_as_votable
|
80
|
+
rubygems_version: 2.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Rails gem to send and save messages via Telegram
|
84
|
+
test_files: []
|