-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ data.txt | |
.apitoken | ||
._* | ||
.token | ||
.otp-data | ||
*.data | ||
*.wasm | ||
|
||
# Test binary, built with `go test -c` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
; Telegram Echo bot | ||
; ~ echoes back the message you send it | ||
|
||
|
@@ -11,3 +11,6 @@ | |
|send bot | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|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 } | ||
|
||
|
||
|
||
|