mirror of
https://github.com/vale981/cl-telegram-bot
synced 2025-03-04 17:21:41 -05:00
Merge branch 'master' of github.com:unwind-protect/cl-telegram-bot
This commit is contained in:
commit
55fa963125
2 changed files with 18 additions and 15 deletions
|
@ -10,7 +10,7 @@ This library has the following aliases: cl-telegram-bot, tl-bot, tg-bot, telegra
|
|||
Returns a bot instance for a given token. To get a new token, see [here](https://core.telegram.org/bots#3-how-do-i-create-a-bot).
|
||||
|
||||
- function `(access object &rest slot-list)`
|
||||
Convenience function to access nested fields in a JSON object. For example, to access update.message.from.id, you can use
|
||||
Convenience function to access nested fields in a JSON object. Returns NIL if at least one slot is unbound. For example, to access update.message.from.id, you can use
|
||||
`(access update 'message 'from 'id)`. This operation is linear in time, so I suggest keeping it at a minimum,
|
||||
reusing the fields multiple times, e.g. using a let*.
|
||||
You can use this function from any JSON field, so `(access message 'from 'id)` from a previously accessed message field
|
||||
|
@ -21,7 +21,7 @@ This library has the following aliases: cl-telegram-bot, tl-bot, tg-bot, telegra
|
|||
`(decode (send-message ...)` returns an object ready to be used (by `access`, for example).
|
||||
|
||||
- function `(get-slot obj slot)`
|
||||
Returns slot from obj, NIL is unbound. Use with JSON CLOS object.
|
||||
Returns slot from obj, NIL if unbound. Use with JSON CLOS object.
|
||||
|
||||
- error `request-error`
|
||||
Used (currently) by get-updates on HTTP error.
|
||||
|
@ -33,12 +33,13 @@ This library has the following aliases: cl-telegram-bot, tl-bot, tg-bot, telegra
|
|||
Make direct API request using Drakma. Use for debugging only.
|
||||
|
||||
- function [`(get-updates bot &key limit timeout)`](https://core.telegram.org/bots/api#getupdates)
|
||||
Returns a vector of updates as CLOS objects.
|
||||
|
||||
NOTE: The offset parameter is omitted as it is internally managed by the tl-bot:bot class.
|
||||
NOTE: The offset parameter is omitted as it is internally managed by the cl-telegram-bot:bot class.
|
||||
|
||||
## API methods
|
||||
|
||||
NOTE: the keyword argument :reply from the official API was renamed to :reply in every function.
|
||||
NOTE: the keyword argument :reply_to_message_id from the official API was renamed to :reply in every function.
|
||||
|
||||
- function [`(set-webhook bot &key url certificate)`](https://core.telegram.org/bots/api#setwebhook)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
; SOFTWARE.
|
||||
; SOFTWARE.
|
||||
|
||||
(in-package :tl-bot)
|
||||
|
||||
|
@ -29,19 +29,21 @@
|
|||
(defclass bot ()
|
||||
((id
|
||||
:documentation "Update id"
|
||||
:initform 0)
|
||||
:initform 0
|
||||
:accessor id)
|
||||
(token
|
||||
:initarg :token
|
||||
:documentation "Bot token given by BotFather"
|
||||
:initform Nil)
|
||||
:initform nil)
|
||||
(endpoint
|
||||
:initarg :endpoint
|
||||
:accessor endpoint
|
||||
:documentation "HTTPS endpoint"
|
||||
:initform Nil)))
|
||||
:initform nil)))
|
||||
|
||||
(defmethod initialize-instance :after ((b bot) &key)
|
||||
(setf (slot-value b 'endpoint)
|
||||
(concatenate 'string +telegram-api-uri+ (slot-value b 'token) "/")))
|
||||
(setf (endpoint b)
|
||||
(concatenate 'string +telegram-api-uri+ (endpoint b) "/")))
|
||||
|
||||
(defun make-bot (token)
|
||||
"Create a new bot instance. Takes a token string."
|
||||
|
@ -57,7 +59,7 @@
|
|||
(defun make-request (b name options)
|
||||
"Perform HTTP request to 'name API method with 'options JSON-encoded object."
|
||||
(drakma:http-request
|
||||
(concatenate 'string (slot-value b 'endpoint) name)
|
||||
(concatenate 'string (endpoint b) name)
|
||||
:method :post
|
||||
:want-stream t
|
||||
:content-type "application/json"
|
||||
|
@ -71,7 +73,7 @@
|
|||
(return-from access nil))
|
||||
(setf current (slot-value current r)))
|
||||
current))
|
||||
|
||||
|
||||
(defun get-slot (update slot)
|
||||
"Access slot. Since fluid classes signal error on unbound slot access, this instead returns nil."
|
||||
(if (slot-boundp update slot)
|
||||
|
@ -95,7 +97,7 @@
|
|||
|
||||
(defun get-updates (b &key limit timeout)
|
||||
"https://core.telegram.org/bots/api#getupdates"
|
||||
(let* ((current-id (slot-value b 'id))
|
||||
(let* ((current-id (id b))
|
||||
(cl-json:*json-symbols-package* :tl-bot)
|
||||
(request
|
||||
(decode (make-request b "getUpdates"
|
||||
|
@ -110,8 +112,8 @@
|
|||
(let* ((last-update (elt results (- (length results) 1)))
|
||||
(id (slot-value last-update 'update--id)))
|
||||
(when (= current-id 0)
|
||||
(setf (slot-value b 'id) id))
|
||||
(incf (slot-value b 'id))))
|
||||
(setf (id b) id))
|
||||
(incf (id b))))
|
||||
results))
|
||||
|
||||
(defun set-webhook (b &key url certificate)
|
||||
|
|
Loading…
Add table
Reference in a new issue