diff options
author | Adrian Kummerlaender | 2016-03-10 22:56:52 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-03-10 22:56:52 +0100 |
commit | cfa925fb53107178c3e346a212c75a77d6c04357 (patch) | |
tree | 7bd7117636d9708f4d2f19248fa467222ec8ce2d | |
parent | 3409325cf635b25036b7132df7e47e767bda65e8 (diff) | |
download | Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar.gz Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar.bz2 Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar.lz Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar.xz Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.tar.zst Telebot-cfa925fb53107178c3e346a212c75a77d6c04357.zip |
Implement simple inefficient echo bot
-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)))) |