aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-03-13 23:07:59 +0100
committerAdrian Kummerlaender2016-03-13 23:07:59 +0100
commit941835c331f16846da6c65f466728e2ed807ca4d (patch)
treefd84cf001e089bf85a8ac58993a41ee75d11181b /example
parent9786703f5602d53acceae972909fce4184cb4142 (diff)
downloadTelebot-941835c331f16846da6c65f466728e2ed807ca4d.tar
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.tar.gz
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.tar.bz2
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.tar.lz
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.tar.xz
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.tar.zst
Telebot-941835c331f16846da6c65f466728e2ed807ca4d.zip
Add extension build and install instructions
Diffstat (limited to 'example')
-rw-r--r--example/echo.scm31
1 files changed, 31 insertions, 0 deletions
diff --git a/example/echo.scm b/example/echo.scm
new file mode 100644
index 0000000..7afd5ae
--- /dev/null
+++ b/example/echo.scm
@@ -0,0 +1,31 @@
+(require-extension telebot
+ (prefix telebot telebot:))
+
+(use data-structures)
+
+(define (resolve-query query tree)
+ (fold (lambda (x y) (alist-ref x y))
+ tree
+ query))
+
+(define token (car (command-line-arguments)))
+
+(define (print-message msg)
+ (print (resolve-query '(message from first_name) msg)
+ ": "
+ (resolve-query '(message text) msg)
+ " ("
+ (resolve-query '(update_id) msg)
+ ")"))
+
+(define (echo-message msg)
+ (let ((chat_id (resolve-query '(message from id) msg))
+ (text (resolve-query '(message text) msg)))
+ (telebot:sendMessage token
+ chat_id: chat_id
+ text: text)))
+
+(telebot:pollUpdates token
+ (lambda (u)
+ (begin (print-message u)
+ (echo-message u))))