Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dx3mod/tgbot
A framework for Telegram Bot API written in OCaml
https://github.com/dx3mod/tgbot
Last synced: 9 days ago
JSON representation
A framework for Telegram Bot API written in OCaml
- Host: GitHub
- URL: https://github.com/dx3mod/tgbot
- Owner: dx3mod
- License: mit
- Created: 2024-08-11T13:59:03.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-11-10T13:14:52.000Z (2 months ago)
- Last Synced: 2024-11-10T14:21:22.349Z (2 months ago)
- Language: OCaml
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TgBot
A framework for [Telegram Bot API](https://core.telegram.org/bots/api) written OCaml
and built on [Lwt] & [Cohttp] libraries.## Usage
### Installation
You can [pin][opam-pin] the upstream version of the library using the [OPAM] package manager.
```console
$ opam pin https://github.com/dx3mod/tgbot.git
```### Echo bot
Typical bot example — "echo bot" sending your message back.
Taken from [examples/echobot.ml](./examples/echobot.ml).```ocaml
(* Your incoming updates dispatcher. *)
module Dispr (Bot : Tgbot.Bot.S) = struct
open Tgbot_api.Types
open Lwt.Infixinclude Tgbot.Dispatcher.Plugs
include Tgbot.Logger.Dev (* log incoming messages *)(* Incoming message handler. *)
let on_message (message : Message.t) =
Bot.send_message ~chat_id:message.chat.id message.text >|= ignore
endlet () =
Lwt_main.run @@
let token = "YOUR TOKEN" in
Tgbot.run_long_polling ~token (module Dispr)
```In the example we use high-level abstraction for handling incoming messages by [dispatcher pattern][dispr-pat]. You can find a more low-level version of the example [here](./examples/lowlevel_echobot.ml).
See more examples in the [`example/`](./examples/) directory.
## See also
- [repostbot] — bot for forwarding user's posts from VK (by [vkashka]) to Telegram chat (by [tgbot])
## Contribution
The is an open source project under the [MIT](./LICENSE) license. Contributions are very welcome!
Please be sure to read the [CONTRIBUTING.md](./CONTRIBUTING.md) before your first commit.[Cohttp]: https://github.com/mirage/ocaml-cohttp
[Lwt]: https://github.com/ocsigen/lwt[OPAM]: https://opam.ocaml.org/
[opam-pin]: https://opam.ocaml.org/doc/Usage.html#opam-pin[dispr-pat]: https://www.researchgate.net/figure/Event-dispatcher-pattern_fig14_242378736
[repostbot]: https://github.com/dx3mod/repostbot
[vkashka]: https://github.com/dx3mod/vkashka
[tgbot]: https://github.com/dx3mod/tgbot