chat_sdk-telegram 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c91f00043b554f53ef31b9c1c73540d7495ed60313802c7f4db3f8e41f6729e
4
- data.tar.gz: 9f081cdebba34e0ecfad397fc72d031770b8ce92ae2cdd0c6c694a3216e7af31
3
+ metadata.gz: 0f7d37715ceea339728711cb2bf73bb3ca54c505ebf41a7ceaefbdd1854855a2
4
+ data.tar.gz: 7c577f6be364fa0590510c0b96cff7e80f06b875ed1961c51e58679b9116aea2
5
5
  SHA512:
6
- metadata.gz: 7e9b5f9eab5c771f56fab8e708d26ffe14a56415add30a4aab5a9b04a61ffc5f64284358c8e8ccf913bb28525e1ccf183352159eb7111572912737c8f0dadf9a
7
- data.tar.gz: 5da8589bb74c1279e6adc239e385aab47fe4e36536b7cd2030e00b443891a9af799f6b7fe883f10459a72a5f7a4df316acd262279e50dcb72a5b054b7d796037
6
+ metadata.gz: 614df50891bcf72c989fcbe7cdab943163bae5ff687085bb1b22a2d9817a8316f6787bca63c99c0dcce7a55db51e7c971992879ef7144be88820a6c207055589
7
+ data.tar.gz: c441e637e325a4819dda8e373bd587377aade11b1ffef58e91232dd68da8c318f84a4e8ea88351691f7cdf27cecf43d31bc0744e1da943893210a5996d77b790
@@ -47,10 +47,7 @@ module ChatSDK
47
47
  end
48
48
 
49
49
  def parse_events(rack_request)
50
- body = rack_request.body.read
51
- rack_request.body.rewind
52
-
53
- payload = JSON.parse(body)
50
+ payload = read_json_body(rack_request)
54
51
  EventParser.parse(payload, bot_username: @bot_username)
55
52
  rescue JSON::ParserError
56
53
  []
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ChatSDK
4
4
  module Telegram
5
- class ApiClient
5
+ class ApiClient < ChatSDK::ApiClient::Base
6
6
  BASE_URL = "https://api.telegram.org"
7
7
 
8
8
  def initialize(bot_token)
@@ -56,55 +56,35 @@ module ChatSDK
56
56
  "/bot#{@bot_token}/#{method}"
57
57
  end
58
58
 
59
- def connection
60
- @connection ||= Faraday.new(url: BASE_URL) do |f|
61
- f.request :json
62
- f.response :json
63
- f.adapter :net_http
64
- end
59
+ def base_url
60
+ BASE_URL
65
61
  end
66
62
 
67
- def upload_connection
68
- @upload_connection ||= Faraday.new(url: BASE_URL) do |f|
69
- f.request :multipart
70
- f.response :json
71
- f.adapter :net_http
72
- end
63
+ def adapter_name
64
+ :telegram
73
65
  end
74
66
 
75
- def request(method, api_method, body = nil)
76
- response = connection.public_send(method, api_path(api_method)) do |req|
77
- req.body = body if body && method != :get
78
- end
67
+ def configure_auth(_faraday)
68
+ # Telegram uses token in URL path, no auth headers needed
69
+ end
79
70
 
80
- handle_response(response)
71
+ def resolve_path(path)
72
+ api_path(path)
81
73
  end
82
74
 
83
- def handle_response(response)
75
+ def extract_success_body(response)
84
76
  body = response.body
77
+ (body.is_a?(Hash) && body["ok"]) ? body["result"] : {}
78
+ end
85
79
 
86
- if response.success? && body.is_a?(Hash) && body["ok"]
87
- return body["result"]
88
- end
89
-
90
- if response.status == 429
91
- retry_after = body.is_a?(Hash) ? body.dig("parameters", "retry_after")&.to_i : nil
92
- raise ChatSDK::RateLimitedError.new(
93
- "Telegram API rate limited",
94
- retry_after: retry_after,
95
- status: response.status,
96
- body: body,
97
- adapter_name: :telegram
98
- )
99
- end
100
-
101
- description = body.is_a?(Hash) ? body["description"] : response.status
102
- raise ChatSDK::PlatformError.new(
103
- "Telegram API error: #{description}",
104
- status: response.status,
105
- body: body,
106
- adapter_name: :telegram
107
- )
80
+ def extract_retry_after(response)
81
+ body = response.body
82
+ body.is_a?(Hash) ? body.dig("parameters", "retry_after")&.to_i : nil
83
+ end
84
+
85
+ def extract_error_message(response)
86
+ body = response.body
87
+ body.is_a?(Hash) ? body["description"] : response.status.to_s
108
88
  end
109
89
  end
110
90
  end
@@ -30,7 +30,7 @@ module ChatSDK
30
30
  msg = ChatSDK::Message.new(
31
31
  id: message["message_id"]&.to_s,
32
32
  text: text,
33
- author: ChatSDK::Author.new(id: user[:id], name: user[:name], platform: :telegram, bot: false),
33
+ author: ChatSDK::Author.new(id: user[:id], name: user[:name], platform: :telegram, bot: false, locale: user[:locale]),
34
34
  thread_id: thread_id,
35
35
  channel_id: chat_id,
36
36
  platform: :telegram,
@@ -63,7 +63,8 @@ module ChatSDK
63
63
  id: user_info["id"]&.to_s || "unknown",
64
64
  name: user_info["username"] || user_info["first_name"] || "unknown",
65
65
  platform: :telegram,
66
- bot: false
66
+ bot: false,
67
+ locale: user_info["language_code"]
67
68
  )
68
69
 
69
70
  [ChatSDK::Events::Action.new(
@@ -82,7 +83,8 @@ module ChatSDK
82
83
  from = message["from"] || {}
83
84
  {
84
85
  id: from["id"]&.to_s || "unknown",
85
- name: from["username"] || from["first_name"] || "unknown"
86
+ name: from["username"] || from["first_name"] || "unknown",
87
+ locale: from["language_code"]
86
88
  }
87
89
  end
88
90
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_sdk-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Rootly
7
+ - Quentin Rousseau
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '2.0'
40
40
  description: Telegram Bot API adapter for the ChatSDK framework
41
41
  email:
42
- - eng@rootly.com
42
+ - quentin@rootly.com
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []