diff options
-rw-r--r-- | bot.scm | 38 |
1 files changed, 29 insertions, 9 deletions
@@ -2,6 +2,7 @@ (import (prefix telebot telebot:)) (use vector-lib) +(use loops) (define (assure-list value) (if (list? value) @@ -21,14 +22,33 @@ (vector-for-each (lambda (i u) (func u)) (cdr updates))) +(define offset 0) (define token (car (command-line-arguments))) -(updates-for-each (lambda (u) - (print (cdr (resolve-query (list 'message 'from 'first_name) u)) - ": " - (cdr (resolve-query (list 'message 'text) u)) - " (" - (cdr (resolve-query (list 'update_id) u)) - ")")) - (resolve-query (list 'result) - (telebot:getUpdates token))) +(define (print-message msg) + (print (cdr (resolve-query (list 'message 'from 'first_name) msg)) + ": " + (cdr (resolve-query (list 'message 'text) msg)) + " (" + (cdr (resolve-query (list 'update_id) msg)) + ")")) + +(define (echo-message msg) + (let ((chat_id (cdr (resolve-query (list 'message 'from 'id) msg))) + (text (cdr (resolve-query (list 'message 'text) msg))) + (message_id (cdr (resolve-query (list 'message 'message_id) msg)))) + (telebot:sendMessage token + chat_id: chat_id + text: text + reply_to_message_id: message_id))) + +(do-forever + (updates-for-each (lambda (u) + (begin (print-message u) + (echo-message u) + (set! offset + (+ 1 (cdr (resolve-query (list 'update_id) u)))))) + (resolve-query (list 'result) + (telebot:getUpdates token + offset: offset + timeout: 60)))) |