sirewix / vktgbot.hs

Simple echo bot for vk and telegram written in haskell
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Echo bot for Telegram & Vk.com

This repo contains my attempt to learn haskell by creating simple echo bot.

stack build
stack test
stack exec bot-exe -- --config .conf

Configuration

The bot can be configured via these three sources in order of decreasing priority:

Command line arguments

Option name is prefixed by --

bot --config .conf --tg.token 123456:AaseDG55y

Environment variables

In the option name . is replaced by _, and the whole name is prefixed with BOT_

BOT_tg_token=123456:AaseDG55y bot

Config file

Use --config parameter to specify config file. It consists of key value pairs, separated by =. Supports comments, starting with # and multiline strings. Quotes " are optional for values.

# Config file for the bot

# tg.proxy  = 127.0.0.1:9080
tg.token  = 1258788986:AAErwZlr

logLevel = Debug

helpText = "
Hi,
what did you wanted?
"

Options

Per API options can be used with tg. or vk. prefix. If used as is the option applied to both API's Option Type Value Default Description
helpText Global String Some text /help command answer
logLevel Per API Debug | Info | Warning | Error Warning Log level
proxy Per API localhost:5000 -- Http proxy host and port
repeatTimes Global Integer 5 Initial number of repetitions
tg.token For Tg API String -- Telegram bot token
vk.groupId For Vk API Integer -- Vkontakte group id
vk.token For Vk API String -- Vkontakte group token

Project structure

Module Description
Bot.API Interface of a bot API
Bot.IO Interface of a bot logic
Bot Bot engine
Deserialization Common JSON deserialization options
EchoBot.Options Echo bot options
EchoBot.State Echo bot state
EchoBot Implementation of the echo bot logic
Logger Logger definition and implementation
Misc Miscellaneous functions
Options Reading options from CLI arguments, environment variables and config file
Telegram.Chat Telegram chat object
Telegram.Message Telegram message object
Telegram.Update Telegram update object
Telegram.User Telegram user object
Telegram Telegram bot API definition
UserData Storing clients data in RAM
Vk.Message Vkontakte message object
Vk.Poll Long poll Vkontakte related stuff
Vk.Update Vkontakte update object
Vk Vkontakte bot API definition