Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Megabot and many pipeline fixes. #25

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
20e7928
Megabot and many pipeline fixes.
svetlyak40wt Dec 22, 2024
c8cb4d6
Complete delete messages from example bots when switching back to the…
svetlyak40wt Dec 24, 2024
8c05ded
Added two more examples to megabot.
svetlyak40wt Dec 26, 2024
bbd8585
Fixed issue when spec's *PARENT* var became NIL after asdf system rel…
svetlyak40wt Dec 26, 2024
767267b
Fixed payments processing for the megabot.
svetlyak40wt Dec 26, 2024
84efb7e
Debug diagram rendering WIP.
svetlyak40wt Jan 1, 2025
676e642
PlantUML diagram refactored.
svetlyak40wt Jan 1, 2025
24bf19b
Made /debug command show workflow diagram.
svetlyak40wt Jan 1, 2025
471f8b6
Output error if var is not set.
svetlyak40wt Jan 1, 2025
3a480e5
Fix doc issues.
svetlyak40wt Jan 1, 2025
e49b557
Added new asdf systems to linter.
svetlyak40wt Jan 1, 2025
8cc2f97
Fixed name of the system to lint.
svetlyak40wt Jan 1, 2025
66a66aa
Updated qlfile.
svetlyak40wt Jan 1, 2025
419fc07
Fixed a warning in mini-app example.
svetlyak40wt Jan 1, 2025
99a460b
Fixed a warning in the spec.lisp.
svetlyak40wt Jan 1, 2025
0a94250
Added documentation section about examples.
svetlyak40wt Jan 3, 2025
3668a1c
Fixed a documentation markup.
svetlyak40wt Jan 3, 2025
9d3ca31
Added doc on calc example.
svetlyak40wt Jan 5, 2025
f03b3b7
Install plantuml for docs building + check imports.
svetlyak40wt Jan 5, 2025
2148259
Fixed missing import.
svetlyak40wt Jan 5, 2025
7165313
Attempt to build docs on ubuntu-24.04.
svetlyak40wt Jan 5, 2025
fefb8b5
Fixed imports in a lot of files.
svetlyak40wt Jan 5, 2025
425b31a
Attempt to fix the linter.
svetlyak40wt Jan 5, 2025
70edeaa
Update PlantUML to a recent version.
svetlyak40wt Jan 5, 2025
6ac3e80
Get rid of njson.
svetlyak40wt Jan 5, 2025
546c8e1
Fixed shell command.
svetlyak40wt Jan 5, 2025
0e69b34
Fixed spec loading.
svetlyak40wt Jan 5, 2025
25983c4
Fixed documentation and imports.
svetlyak40wt Jan 6, 2025
77f5448
Fixed boolean arguments processing.
svetlyak40wt Jan 7, 2025
fae888b
Mini-app example now configurable via env variables.
svetlyak40wt Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
"jobs": {
"build-docs": {
"runs-on": "ubuntu-latest",
"runs-on": "ubuntu-24.04",
"env": {
"OS": "ubuntu-latest",
"OS": "ubuntu-24.04",
"QUICKLISP_DIST": "quicklisp",
"LISP": "sbcl-bin"
},
Expand All @@ -32,10 +32,19 @@
"with": {
"asdf-system": "cl-telegram-bot-docs",
"dynamic-space-size": "4gb",
"cache": "true",
"cache-suffix": "dyn-space"
"cache": "true"
}
},
{
"name": "Install PlantUML",
"run": "sudo apt-get install -y plantuml",
"shell": "bash"
},
{
"name": "Update PlantUML",
"run": "sudo curl --output /usr/share/plantuml/plantuml.jar -L https://github.com/plantuml/plantuml/releases/download/v1.2024.8/plantuml-mit-1.2024.8.jar",
"shell": "bash"
},
{
"name": "Build Docs",
"uses": "40ants/build-docs@v1",
Expand All @@ -47,4 +56,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
{
"name": "Run Linter",
"run": "qlot exec 40ants-linter --system \"cl-telegram-bot, cl-telegram-bot-docs, cl-telegram-bot-tests\"",
"run": "qlot exec 40ants-linter --system \"cl-telegram-bot, cl-telegram-bot2, cl-telegram-bot2-examples, cl-telegram-bot-tests\" --imports",
"shell": "bash"
}
]
Expand Down
8 changes: 2 additions & 6 deletions cl-telegram-bot2-examples.asd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#-asdf3.1 (error "cl-telegram-bot requires ASDF 3.1 because for lower versions pathname does not work for package-inferred systems.")
(defsystem "cl-telegram-bot2-examples"
:description "Telegram Bot API, based on sovietspaceship's work but mostly rewritten."
:description "Examples of Telegram Bot API Common Lisp library."
:author "Alexander Artemenko <[email protected]>"
:license "MIT"
:homepage "https://40ants.com/cl-telegram-bot/"
Expand All @@ -10,9 +10,5 @@
:defsystem-depends-on ("40ants-asdf-system")
:pathname "examples"
:depends-on ("clack-handler-hunchentoot"
"cl-telegram-bot2-examples/calc"
"cl-telegram-bot2-examples/commands"
"cl-telegram-bot2-examples/gallery"
"cl-telegram-bot2-examples/payments"
"cl-telegram-bot2-examples/mini-app")
"cl-telegram-bot2-examples/all")
:in-order-to ((test-op (test-op "cl-telegram-bot2-tests"))))
13 changes: 2 additions & 11 deletions cl-telegram-bot2.asd
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@
:in-order-to ((test-op (test-op "cl-telegram-bot2-tests"))))


(defsystem "cl-telegram-bot2/deps"
:description "Utility system to load non-package-inferred systems using package-inferred imports."
:author "Alexander Artemenko <[email protected]>"
:license "MIT"
:homepage "https://40ants.com/cl-telegram-bot/"
:source-control (:git "https://github.com/40ants/cl-telegram-bot")
:bug-tracker "https://github.com/40ants/cl-telegram-bot/issues"
:depends-on ("njson/jzon"))


(asdf:register-system-packages "bordeaux-threads" '("BORDEAUX-THREADS-2"))
(asdf:register-system-packages "log4cl" '("LOG"))
(asdf:register-system-packages "utilities.print-items" '("PRINT-ITEMS"))
(asdf:register-system-packages "dexador" '("DEX"))
(asdf:register-system-packages "sento" '("SENTO.ACTOR-SYSTEM"
"SENTO.ACTOR-CONTEXT"
"SENTO.ACTOR"))
"SENTO.ACTOR"
"SENTO.ACTOR-CELL"))
26 changes: 26 additions & 0 deletions docs/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@
"REPL"
"CL-TELEGRAM-BOT/MESSAGE:REPLY"
"HTTP"))
(0.8.0 2025-01-02
"
Changed
=======

* Combined all examples into one megabot.

Added
=====

* New action for message deletion was added. Create it
using CL-TELEGRAM-BOT2/ACTIONS/DELETE-MESSAGES:DELETE-MESSAGES function.
It is able to delete messages send by bot and messages received from user as well.
By default, both message types are deleted.
* Added :ON-DELETION argument to the CL-TELEGRAM-BOT2/STATE:STATE function.
* Added a new feature allowing to render the workflow diagram of the botc.

Fixed
=====

* Inline keyboard high level constructor was fixed.
* Fixed race-conditions in threads stopping code.
* Fixed issues in pipeline processing when sent messages were not saved to the current state.
* Fixed issue with global command processing in case if there is a state which does not support command processing. But to make global commands work, you still need to ensure that current state has a correct mixin.

")
(0.7.0 2024-12-14
"
Huge Changes
Expand Down
71 changes: 71 additions & 0 deletions docs/examples.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
(uiop:define-package #:cl-telegram-bot-docs/examples
(:use #:cl)
(:import-from #:40ants-doc
#:defsection)
(:import-from #:40ants-doc-plantuml
#:defdiagram)
(:import-from #:cl-telegram-bot2/debug/diagram
#:workflow-to-text)
(:import-from #:cl-telegram-bot2-examples/calc))
(in-package #:cl-telegram-bot-docs/examples)


(defsection @examples (:title "Examples")
"Directory [examples](https://github.com/40ants/cl-telegram-bot/tree/master/examples) contains
code of all v2 examples. There are different kinds of bots:

- calc - shows how to switch states while collecting information from user and how to return results back to initial state.
- commands - shows how to bind commands to the telegram bot states.
- echo - a simple bot which replies with the same text.
- gallery - demonstrates how to show an image with inline keyboard and how to edit this message, replacing the image when users has switched to the next one.
- mini-app - this example starts a web-server and opens a mini-app inside the Telegram messenger.
- payments - a demo showing how to send an invoice and to process a payment. You will need to register your own payment provider in the BotFather and to change provider token in the bot's code.
- text-chain - a simple demo changing states each type bot receives a message.

All these examples can be run on their own or as a part of the bigger Megabot. See @RUNNING section to learn how to run the Megabot.
"
(@running section)
(@calc section))


(defsection @running (:title "Running Examples")
"
To run a bot combining all examples, register some bot at BotFather, then do:

```
CL-USER> (ql:quickload :cl-telegram-bot2-examples)

CL-USER> (setf (uiop:getenv \"TELEGRAM_TOKEN\")
\"520*****:AAH*****\")

CL-USER> (cl-telegram-bot2-examples:start)
```

")


(defsection @calc (:title "Calc Example")
"

Example in the calc.lisp file consist of 3 types of the state.

In it's first state it greets the user and then switches to the next state
where it awaits while user will provide a number. Then it switches to the next
state where waits for another number and finally to the state where user should
choose one of the arithmetic operations:

![](asdf:cl-telegram-bot-media:images/examples/calc-bot.gif)

If we'll use /debug command to draw the diagram of the state transitions, then
it will show a picture like this:

"

(@calc-states diagram))



(defdiagram @calc-states ()
(workflow-to-text
(cl-telegram-bot2-examples/calc::make-test-bot "")))

10 changes: 8 additions & 2 deletions docs/index.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#:defautodoc)
(:import-from #:cl-telegram-bot-docs/tutorial
#:@first-bot)
(:import-from #:cl-telegram-bot-docs/examples
#:@examples)
(:export #:@index
#:@readme
#:@changelog))
Expand All @@ -43,6 +45,7 @@
:root-sections '(@index
@first-bot
@states-and-actions
@examples
@api-v2
@v1)))

Expand Down Expand Up @@ -190,6 +193,9 @@ And start communicating with him:

(defautodoc @api-v2 (:title "API v2"
:system :cl-telegram-bot2
:ignore-words ("CL-TELEGRAM-BOT2/API:PRE-CHECKOUT-QUERY-INVOICE-PAYLOAD"
:ignore-words (
;; "CL-TELEGRAM-BOT2/API:PRE-CHECKOUT-QUERY-INVOICE-PAYLOAD"
;; "CL-TELEGRAM-BOT2/API:INLINE-KEYBOARD-MARKUP"
;; "CL-TELEGRAM-BOT2/API:REPLY-KEYBOARD-MARKUP"
"API")
:ignore-packages ("cl-telegram-bot2/api")))
:ignore-packages ("CL-TELEGRAM-BOT2/API")))
16 changes: 8 additions & 8 deletions docs/tutorial.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Note, the bot was started and a function which can stop it was returned from CL-

Now let's see how our bot will behave:

![](asdf:cl-telegram-bot-media:images/tutorial-1.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-1.gif)

As you can see, our bot greets the user but does not respond ot it's message. What if we'll use SEND-TEXT function to create
an action for update event?
Expand All @@ -71,9 +71,9 @@ CL-USER> (setf *stop-func*

Now our bot will respond to the message with a static message:

![](asdf:cl-telegram-bot-media:images/tutorial-2.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-2.gif)

Good! But what if we want to execute some custom logic before reponse? The one way is to define your own action class, but the easiest way
Good! But what if we want to execute some custom logic before response? The one way is to define your own action class, but the easiest way
is to use a function. For demonstration, we'll create a function which will reply with a reversed text:

```
Expand All @@ -98,7 +98,7 @@ CL-USER> (setf *stop-func*
:on-update 'reply-with-reversed-text))))
```

![](asdf:cl-telegram-bot-media:images/tutorial-3.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-3.gif)

Now let's combine two actions together. First we'll send a static text, then call a function
and send the reversed user input:
Expand All @@ -120,7 +120,7 @@ CL-USER> (setf *stop-func*
'reply-with-reversed-text)))))
```

![](asdf:cl-telegram-bot-media:images/tutorial-4.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-4.gif)

As we said in the beginning of the tutorial, the real power of the second version of cl-telegram-bot is
it's ability to keep context as the current state. At the next step we'll create the second state at which
Expand Down Expand Up @@ -167,7 +167,7 @@ CL-USER> (setf *stop-func*
```


![](asdf:cl-telegram-bot-media:images/tutorial-5.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-5.gif)

As you can see, now our bot has stuck in the second state and there is no way to jump back to the first one.
How would we do this?
Expand Down Expand Up @@ -211,7 +211,7 @@ CL-USER> (setf *stop-func*
(cl-telegram-bot2/term/back:back))))))))
```

![](asdf:cl-telegram-bot-media:images/tutorial-6.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-6.gif)

As you can see, now bot switches between first and second states. But `back` function can do more, because
this kind of actions are special and is able not only to switch current bot's state, but also to return some
Expand Down Expand Up @@ -269,7 +269,7 @@ CL-USER> (setf *stop-func*
:on-result 'process-result))))
```

![](asdf:cl-telegram-bot-media:images/tutorial-7.gif)
![](asdf:cl-telegram-bot-media:images/tutorial/tutorial-7.gif)

This is all for now. In the next tutorial we'll see how to define a custom states to make some building blocks for our workflow.

Expand Down
Loading
Loading