Skip to content

Commit

Permalink
added first telegram examples
Browse files Browse the repository at this point in the history
  • Loading branch information
refaktor committed Oct 12, 2023
1 parent 6b6bf70 commit 4f8407d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ data.txt
.apitoken
._*
.token
.otp-data
*.data
*.wasm

# Test binary, built with `go test -c`
Expand Down
5 changes: 4 additions & 1 deletion examples-wip/telegram-bot/echo-bot.rye
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

; Telegram Echo bot
; ~ echoes back the message you send it

Expand All @@ -11,3 +11,6 @@
|send bot
}




9 changes: 9 additions & 0 deletions examples-wip/telegram-bot/probe-bot.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

rye .needs { 'telegram }

new-telegram-bot trim read %.token
|on-update { .probe }




55 changes: 55 additions & 0 deletions examples-wip/telegram-bot/rye-shell-bot.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

; !!! WARNING !!!
; Don't run this for anything more than a short demo, as it would allow anyone
; with access to this bot to execute any Rye command on your computer!
; All commands are printed out in console. In next steps we will create a safer
; version of a bot using this as a basis.
; !!! WARNING !!!

rye .needs { 'telegram }

bot: new-telegram-bot trim read %.token

shell: context {

i-am: fn { name } { "Hi " + name }

add: fn { a b } { a + b }

warning: fn { x } { "Uh, this is bad!" }

}

produce-reply: fn { msg } {
load msg/text
|print
|do-in* shell
}

; helper functions

extract-message: fn { telegram-update-obj } {
-> "Message" :msg
context { msg -> "Chat" -> "ID" :id , msg -> "Text" :text }
}

reply: fn { text msg bot } {
new-telegram-message msg/id to-string text
|send bot
}

; msg update loop

bot .on-update { .extract-message :msg |produce-reply |reply msg bot }







; bot .on-update { .probe }




0 comments on commit 4f8407d

Please sign in to comment.