File tree Expand file tree Collapse file tree
src/marksto/clj_tg_bot_api
test/integration/marksto/clj_tg_bot_api Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 [marksto.clj-tg-bot-api.impl.api.martian :as api-martian]
1010 [marksto.clj-tg-bot-api.impl.client.rate-limiter :as rl]
1111 [marksto.clj-tg-bot-api.impl.utils :as utils]
12+ [marksto.clj-tg-bot-api.impl.utils.bot :as bot]
1213 [marksto.clj-tg-bot-api.impl.utils.response :as response])
1314 (:import (java.io Writer)))
1415
3940
4041(def global-server-url " https://api.telegram.org/bot" )
4142
42- (defn parse-bot-id [bot-token]
43- (try
44- (parse-long (subs bot-token 0 (str/index-of bot-token \:)))
45- (catch Exception ex
46- (throw (ex-info " Failed to parse an ID from the bot auth token" {} ex)))))
47-
4843(defn ->client
4944 [{:keys [bot-token server-url responses limiter-opts interceptors]
5045 :or {server-url global-server-url
6055 (-> (mt/respond-with responses)
6156 ; ; TODO: Drop this temp patch when Martian PR #243 is merged.
6257 (update :interceptors vec)))
63- (assoc :bot-id (parse-bot-id bot-token)
58+ (assoc :bot-id (bot/ parse-bot-id bot-token)
6459 :limiter-opts limiter-opts)
6560 (with-meta {:type ::tg-bot-api-client })))
6661
Original file line number Diff line number Diff line change 1+ (ns marksto.clj-tg-bot-api.impl.utils.bot
2+ (:require [clojure.string :as str]))
3+
4+ (defn parse-bot-id
5+ [bot-token]
6+ (try
7+ (parse-long (subs bot-token 0 (str/index-of bot-token \:)))
8+ (catch Exception ex
9+ (throw (ex-info " Failed to parse an ID from the bot auth token" {} ex)))))
10+
11+ (defn mask-bot-token
12+ [bot-token mask-str]
13+ (str (parse-bot-id bot-token) \: mask-str))
Original file line number Diff line number Diff line change 11(ns marksto.clj-tg-bot-api.utils
22 " Some utilities for Telegram Bot API types, updates and responses"
3- (:require [marksto.clj-tg-bot-api.impl.utils.types :as types]
3+ (:require [marksto.clj-tg-bot-api.impl.utils.bot :as bot]
4+ [marksto.clj-tg-bot-api.impl.utils.types :as types]
45 [marksto.clj-tg-bot-api.impl.utils.update :as update]
56 [marksto.clj-tg-bot-api.impl.utils.response :as response]))
67
8+ ; ;;; BOT
9+
10+ (defn parse-bot-id
11+ " Retrieves a Telegram Bot ID from a plain `bot-token` string.
12+ Useful during tests, e.g. when mocking the Telegram Bot API."
13+ [bot-token]
14+ (bot/parse-bot-id bot-token))
15+
16+ (defn mask-bot-token
17+ " Masks the sensitive portion of the given `bot-token` string."
18+ ([bot-token]
19+ (bot/mask-bot-token bot-token " ..." ))
20+ ([bot-token mask-str]
21+ (bot/mask-bot-token bot-token mask-str)))
22+
723; ;;; TYPES
824
925; ;; Date/Time
Original file line number Diff line number Diff line change 22 (:require [clojure.string :as str]
33 [clojure.test :refer [deftest is testing use-fixtures]]
44 [marksto.clj-tg-bot-api.core :as sut]
5- [marksto.clj-tg-bot-api.impl.client.core :as client ]
5+ [marksto.clj-tg-bot-api.utils :as utils ]
66 [marksto.clj-tg-bot-api.impl.api.martian :as api-martian]
77 [marksto.clj-tg-bot-api.net-utils :as net-utils]
88 [marksto.clj-tg-bot-api.vcr-utils :as vcr-utils]
1111
1212(def real-bot-token (or (System/getenv " BOT_AUTH_TOKEN" )
1313 (throw (ex-info " Missing BOT_AUTH_TOKEN env var" {}))))
14- (def real-bot-id (client /parse-bot-id real-bot-token))
14+ (def real-bot-id (utils /parse-bot-id real-bot-token))
1515
1616(def fake-bot-token " 1234567890:TEST_pxWA8lDi7uLc3oadqNivHCALHBQ7sM" )
17- (def fake-bot-id (client /parse-bot-id fake-bot-token))
17+ (def fake-bot-id (utils /parse-bot-id fake-bot-token))
1818
1919(def replacements
2020 [[:string-val real-bot-token fake-bot-token]
You can’t perform that action at this time.
0 commit comments