Skip to content
/ tgbot Public

A framework for Telegram Bot API written in OCaml

License

Notifications You must be signed in to change notification settings

dx3mod/tgbot

Repository files navigation

TgBot

A framework for Telegram Bot API written OCaml and built on Lwt & Cohttp libraries.

Usage

Installation

You can pin the upstream version of the library using the OPAM package manager.

$ opam pin https://github.com/dx3mod/tgbot.git

Echo bot

Typical bot example — "echo bot" sending your message back. Taken from examples/echobot.ml.

(* Your incoming updates dispatcher. *)
module Dispr (Bot : Tgbot.Bot.S) = struct
  open Tgbot_api.Types
  open Lwt.Infix

  include 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
end

let () =
  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. You can find a more low-level version of the example here.

See more examples in the example/ directory.

See also

Contribution

The is an open source project under the MIT license. Contributions are very welcome! Please be sure to read the CONTRIBUTING.md before your first commit.

About

A framework for Telegram Bot API written in OCaml

Resources

License

Stars

Watchers

Forks