High-level bindings to the Telegram Bot API based on servant library.Both getUpdates
request or webhook can be used to receive updates for your bot.Inline mode is supported.Uploading stickers, documents, video, etc is not supported yet, but you can send items which are already uploaded on the Telegram servers.
Support of Bot-3.5 API
There are two ways of using Telegram Bot API. First and original way is to run IO directly for every Telegram servers request, another one is based on TelegramClient
which is just ReaderT
.
TelegramClient
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Web.Telegram.API.Bot
main :: IO ()
main = do
let token = Token "bot<token>" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
manager <- newManager tlsManagerSettings
result <- runTelegramClient token manager $ do
info <- getWebhookInfoM
let request = setWebhookRequest' "https://example.com/hook"
isSet <- setWebhookM request
getMeM
print result
print "done!"
M
versions. You can run them using runTelegramClient
function, for example runTelegramClient token manager $ sendMessageM message
or in example below replace getMe token manager
with runTelegramClient token manager getMeM
to get the same behavior.
getMe
example
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Web.Telegram.API.Bot
main :: IO ()
main = do
manager <- newManager tlsManagerSettings
res <- getMe token manager
case res of
Left e -> do
putStrLn "Request failed"
print e
Right Response { result = u } -> do
putStrLn "Request succeded"
print $ user_first_name u
where token = Token "bot<token>" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
sendMessage
example
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Web.Telegram.API.Bot
main :: IO ()
main = do
manager <- newManager tlsManagerSettings
let request = sendMessageRequest chatId message
res <- sendMessage token request manager
case res of
Left e -> do
putStrLn "Request failed"
print e
Right Response { result = m } -> do
putStrLn "Request succeded"
print $ message_id m
print $ text m
where token = Token "bot<token>" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
chatId = ChatId <chat_id> -- use ChatId 10231 or ChatChannel "<@channelusername>"
message = "text *bold* _italic_ [github](github.com/klappvisor/haskell-telegram-api)"
Many request data records have a lot of optional parameters which are usually redundant.There are two ways to create requests:
With data type constructor:
let request = SendMessageRequest (ChatId int64_chatId) "text" Nothing (Just True) Nothing Nothing Nothing
Using default instance:
let request = sendMessageRequest (ChatId int64_chatId) "text" -- only with required fields
let request = (sendMessageRequest ChatId int64_chatId) "text") {
message_disable_notification = Just True -- with optional fields
}
Contributions are welcome!
Bear in mind that the CI build won't run integration test suite against your pull request since the necessary environmentvariables ($BOT_TOKEN
, $STRIPE_TOKEN
, $CHAT_ID
and $BOT_NAME
) aren't exported when a forkstarts the build (for security reasons). If you do want to run them before creating RP, you can setup integration of your forkwith CircleCI.
You can use stack
to build project
stack build
To run test you have to create your own bot. Go to BotFather and create the bot. As the result you will have private bot's access token. Keep it safe!
stack test --test-arguments "--integration -c CHAT_ID -b BOT_NAME -- HSPEC_ARGS"
where
BOT_TOKEN
is the token obtained from BotFather and must be defined as environment variablePAYMENT_TOKEN
is the token obtained from BotFather and must be defined as environment variableCHAT_ID
can be id of your chat with your bot. Send some messages to this chat in Telegram and do curl "https://api.telegram.org/bot<replace_with_token>/getUpdates"
, you'll have to parse some JSON with your brain ;-) or any other suitable tool and you will find chat id there.BOT_NAME
is the name of your botHSPEC_ARGS
are the normal hspec
arguments you can find hereThe help option is available for the tests and for hspec:
stack test --test-arguments "-h"
stack test --test-arguments "--integration -c CHAT_ID -b BOT_NAME -- -h"
Note: Inline Spec is disabled for now...
If everything is fine after running the tests you will receive a few new messages from your bot.
三好学生 · 2016/05/27 9:37 0x00 前言 在Github上,涉及到将社交网络作为C2 server(可理解为命令控制服务器)的poc项目越来越多,如利用gmail的gcat、gdog,利用twitter的twittor、以及利用Telegram的Blaze Telegram Backdoor Toolkit (bt2),使用这类方法的好处不仅仅是因为社交网络的服务器稳定,更多的
Telegram Messenger是一个跨平台的即时通讯软件,它的客户端是自由及开放源代码软件,但是它的服务器是专有软件。使用者可以相互交换加密与自解构的讯息,以及相片、影片、文件,支援所有的档案类型。官方网站有正式发布Android、iOS、Mac OS X与正在Beta的Windows Phone的版本;其他版本皆为非正式的版本,而且是由独立研发人员利用官方的应用程序接口来开发的。
telegram-list Список интересных групп, каналов и ботов телеграма. Чаты Telegram для программистов и разработчиков, гиков, айтишников, сисадминов и девопсов, а также прочих неравнодушных к компьютерам
Homebridge Plugin for Telegram Bots A platform that provides configurable Telegram Bots and integratesthem with HomeKit via Homebridge. Status Why a Telegram Bot? This plugin enables you to send Teleg
Telegram Shell Bot 是一个远程执行 Shell 命令的 Telegram 机器人。 Telegram Shell Bot 目前提供的功能有: 鉴权,只有在许可列表里的用户才能对机器人发号指令。 支持命令的黑白名单。注:为避免使用 ; 跳过命令检查,类似的字符也应当加到字符串黑名单中。 Shell 命令的执行,如 ls、cat、ps 等。 长时间执行命令的管理。如执行 wget 操
We have made you a wrapper you can't refuse We have a vibrant community of developers helping each other in our Telegram group. Join us! Stay tuned for library updates and new releases on our Telegram
Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an HTTP-based interface created for developers keen o