A simple and pure API implementation for the Telegram Bot API in Haskell. It aims to provide a type-safe way to build Telegram bots using Haskell's strong type system, making it easy to create maintainable and robust bots.
- Simple to use
- Helps to build a type-safe Telegram bot
- Utilizes Haskell's type safety to create awesome, maintainable, and easy-to-implement bots
This repo Basically defines a Bot data type that represents a Telegram bot and provides functions for constructing and interacting with the Telegram bot API. The module includes functions for making HTTP requests to the Telegram API which take Bot as an argument.
The Bot can be accessed throught the BotBuilder data type which is an implementation of the builder design pattern. BotBuilder is a minimal representation of the Bot type without including private fields. It provides a constructor initBot for creating a BotBuilder with an empty token, and a withToken function for setting the token on a BotBuilder instance. The buildBot function is used to convert a BotBuilder instance to a Bot instance.
import Bot
builder :: BotBuilder
builder = initBot
-- Add the token to the builder
builderWithToken :: BotBuilder
builderWithToken =
withToken
"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
builder
-- Build the Bot instance
myBot :: Bot
myBot = buildBot builder
All the Telegram bot methods are (will be) implemented. so you can use each method like this
updates :: IO (Either BotError [Update])
updates = getUpdates
is similar to
curl https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getUpdates
This project is released under the MIT License.
This library is currently compatible with GHC version 9 and above
Please report any bugs or issues in the Issue Tracker.