tg-bot 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 948ec1f7ca8d968e301a9adf6bb6d6716351ed81dab9a020d2aa7dbfb39b3547
4
- data.tar.gz: cde58adfb1cc74599daaf2a52448c0f12cc978a7c9ea062b3a6a586a86745693
3
+ metadata.gz: 108f9e08de4bafac75a4442e22b5de73cd8352b01deea0cd33de18a37b2538d5
4
+ data.tar.gz: 2885cf965a35f343ab6aef795178c4fc19e143a9388c7c100679c4e356e054a3
5
5
  SHA512:
6
- metadata.gz: 5aa028c4f2ab9df294b0aa3448dec0224c368fca7e7ba5cf3c13343d4a1b89f99a6ebe79684ef156ffc8036be09350cce5592703b80d949f35a4d97e9163cc79
7
- data.tar.gz: 4d842828909844db7173758109f91931afd8e98ec04a673d9fb6da795261b345d8024f16c4ade3930e620821cd0ad58912bae94c66c351d87995715e03be20d2
6
+ metadata.gz: 2b9d0b07ee205c9225913e3eea1875dce6e14b4302442f555b29eb543e6b61cba4b53392d6ba9f50a7550b4947cd5942542c42f25560c60b967907aae13aebfa
7
+ data.tar.gz: 71cfea3a551f2c87663423607551de9041cb47b5abbe35b4e495762cb17ed80be23743a80784066d3c3e03c1c4fdb76a2ab8946831f30d2d273441bea1bdfcf5
data/README.md CHANGED
@@ -19,14 +19,14 @@
19
19
  > e.g. my webhook is https://xxxxx/telegram
20
20
  ```ruby
21
21
  def telegram
22
- telegram = Telegram::Bot.new(params)
22
+ telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token'])
23
23
  end
24
24
  ```
25
25
 
26
26
  4. It has 3 ways to reply message
27
27
  ```ruby
28
28
  def telegram
29
- telegram = Telegram::Bot.new(params)
29
+ telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token'])
30
30
 
31
31
  # 1. reply text message
32
32
  telegram.send_message(text: 'enter what you want to reply')
@@ -45,14 +45,14 @@
45
45
  ## [SetWebhook](https://github.com/VenseChang/telegram-bot-gem/blob/4b896317db7804cf8f5191974f5e942872300ba3/lib/tg-bot.rb#L25-L28)
46
46
  ```ruby
47
47
  def xxx
48
- Telegram::Bot::SetWebhook(url)
48
+ Telegram::Bot::SetWebhook(url: url, token: ENV['telegram_bot_token'])
49
49
  end
50
50
  ```
51
51
 
52
52
  ## [Send Message](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/send_message.rb)
53
53
  ```ruby
54
54
  def telegram
55
- telegram = Telegram::Bot.new(params)
55
+ telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token'])
56
56
  telegram.send_message(
57
57
  chat_id: 'chat_id',
58
58
  text: 'Enter you want to reply message text',
@@ -76,7 +76,7 @@ end
76
76
  ## [Forward Message](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/forward_message.rb)
77
77
  ```ruby
78
78
  def telegram
79
- telegram = Telegram::Bot.new(params)
79
+ telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token'])
80
80
  telegram.forward_message(
81
81
  chat_id: 'chat_id',
82
82
  from_chat_id: 'chat_id from forward message',
@@ -95,7 +95,7 @@ end
95
95
  ## [Send Photo](https://github.com/VenseChang/telegram-bot-gem/blob/develop/lib/telegram/reply/send_photo.rb)
96
96
  ```ruby
97
97
  def telegram
98
- telegram = Telegram::Bot.new(params)
98
+ telegram = Telegram::Bot.new(params: params, telegram_bot_token: ENV['telegram_bot_token'])
99
99
  telegram.send_photo(
100
100
  chat_id: 'chat_id',
101
101
  photo: 'InputFile / File Id(String) / HTTP URL(String)',
@@ -5,7 +5,7 @@ module Telegram
5
5
  module Reply
6
6
 
7
7
  def forward_message(chat_id: @chat.id, from_chat_id:, message_id:, **options)
8
- url = Telegram::URL::FORWARD_MESSAGE
8
+ url = Telegram::URL.new(@telegram_bot_token).forward_message
9
9
  params = {
10
10
  chat_id: chat_id,
11
11
  from_chat_id: from_chat_id,
@@ -5,7 +5,7 @@ module Telegram
5
5
  module Reply
6
6
 
7
7
  def send_message(chat_id: @chat.id, text:, parse_mode: 'html', **options)
8
- url = Telegram::URL::SEND_MESSAGE
8
+ url = Telegram::URL.new(@telegram_bot_token).send_message
9
9
  params = {
10
10
  chat_id: chat_id,
11
11
  text: text,
@@ -5,7 +5,7 @@ module Telegram
5
5
  module Reply
6
6
 
7
7
  def send_photo(chat_id: @chat.id, photo:, **options)
8
- url = Telegram::URL::SEND_PHOTO
8
+ url = Telegram::URL.new(@telegram_bot_token).send_photo
9
9
  params = {
10
10
  chat_id: chat_id,
11
11
  photo: photo,
@@ -1,8 +1,19 @@
1
1
  module Telegram
2
- module URL
3
- BASE_URL = "https://api.telegram.org/bot#{ENV['telegram_bot_token']}".freeze
4
- SEND_MESSAGE = "#{BASE_URL}/sendMessage".freeze
5
- FORWARD_MESSAGE = "#{BASE_URL}/forwardMessage".freeze
6
- SEND_PHOTO = "#{BASE_URL}/sendPhoto".freeze
2
+ class URL
3
+ def initialize(token)
4
+ @BASE_URL = "https://api.telegram.org/bot#{token}".freeze
5
+ end
6
+
7
+ def send_message
8
+ [@BASE_URL, 'sendMessage'].join('/')
9
+ end
10
+
11
+ def forward_message
12
+ [@BASE_URL, 'forwardMessage'].join('/')
13
+ end
14
+
15
+ def send_photo
16
+ [@BASE_URL, 'sendPhoto'].join('/')
17
+ end
7
18
  end
8
19
  end
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ module Telegram
8
8
 
9
9
  attr_reader :user, :forward_from, :chat, :forward_from_chat, :message, :text
10
10
 
11
- def initialize(params)
11
+ def initialize(params:, telegram_bot_token:)
12
12
  # User
13
13
  @user = Telegram::Params::From.new(params)
14
14
  @forward_from = Telegram::Params::ForwardFrom.new(params)
@@ -22,11 +22,14 @@ module Telegram
22
22
 
23
23
  # Text
24
24
  @text = @message.text
25
+
26
+ # Token
27
+ @telegram_bot_token = telegram_bot_token
25
28
  end
26
29
 
27
30
  class << self
28
- def SetWebhook(url)
29
- uri = URI("https://api.telegram.org/bot#{ENV['telegram_bot_token']}/setWebhook?url=#{url}")
31
+ def SetWebhook(url:, token:)
32
+ uri = URI("https://api.telegram.org/bot#{token}/setWebhook?url=#{url}")
30
33
  Net::HTTP.get(uri)
31
34
  end
32
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tg-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vense Chang