All Projects → klappvisor → Haskell Telegram Api

klappvisor / Haskell Telegram Api

Licence: other
Telegram Bot API for Haskell

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Haskell Telegram Api

Java Telegram Bot Api
Telegram Bot API for Java
Stars: ✭ 819 (+345.11%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Mypackbot
🤖 Your own unlimited pack of Telegram-stickers
Stars: ✭ 18 (-90.22%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Informer
A Telegram Mass Surveillance Bot in Python
Stars: ✭ 745 (+304.89%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Zanzara
Asynchronous PHP Telegram Bot Framework built on top of ReactPHP
Stars: ✭ 107 (-41.85%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Telegram.bot
.NET Client for Telegram Bot API
Stars: ✭ 1,964 (+967.39%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Spytrojan keylogger
[Solo para programadores] Troyano espía | Keylogger solo para Windows, se replica en el sistema y se inicia automaticamente al iniciar sesión. | Envío de registro mediante [Base de Datos], [Gmail] o [BotTelegram].
Stars: ✭ 32 (-82.61%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Aiogram
Is a pretty simple and fully asynchronous framework for Telegram Bot API written in Python 3.7 with asyncio and aiohttp.
Stars: ✭ 2,195 (+1092.93%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+1102.17%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Telebot
The easy way to write Telegram bots in Node.js
Stars: ✭ 1,096 (+495.65%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Bot Telegram
Exemplo de como criar um BOT para o melhor app de mensagens do mundo: Telegram.
Stars: ✭ 53 (-71.2%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Telebot.nim
Async client for Telegram Bot API in pure Nim [Bot API 5.1]
Stars: ✭ 93 (-49.46%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (-10.33%)
Mutual labels:  telegram-bot-api, bot, telegram-bot
Micro Bot
🤖 Zero-configuration Telegram bot runner
Stars: ✭ 173 (-5.98%)
Mutual labels:  bot, telegram-bot
Android Tg Bot
Awesome Telegram Bot (Android Application)
Stars: ✭ 105 (-42.93%)
Mutual labels:  telegram-bot-api, telegram-bot
Telebot
Write Telegram bots in Rust with Tokio and Futures
Stars: ✭ 179 (-2.72%)
Mutual labels:  bot, telegram-bot
Hackernewsbot
📰 Telegram bot that posts new hot stories from Hacker News to telegram channel
Stars: ✭ 103 (-44.02%)
Mutual labels:  bot, telegram-bot
Novagram
An Object-Oriented PHP library for Telegram Bots
Stars: ✭ 112 (-39.13%)
Mutual labels:  bot, telegram-bot
Telegram Clonebot
Simple Bot to clone Google Drive Files (or Folders) to your Team Drive[or Normal Drive]. P.S This is not a Mirror Bot. Enjoy ✌🏻
Stars: ✭ 114 (-38.04%)
Mutual labels:  bot, telegram-bot
Telegram Robot Rss
A clean and easy to use RSS Newsfeed Bot for fabulous Telegram Messenger App! 🤖 ✉️ ❤️
Stars: ✭ 120 (-34.78%)
Mutual labels:  bot, telegram-bot
Vk To Telegram Bot
Bot for auto-reposting posts from VK to Telegram channel
Stars: ✭ 103 (-44.02%)
Mutual labels:  telegram-bot-api, telegram-bot

telegram-api

Join the chat at https://gitter.im/klappvisor/haskell-telegram-api

Build Status Hackage Hackage Dependencies Haskell Programming Language BSD3 License

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

Usage

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.

Use 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!"

Running IO directly (planning to deprecate this option)

⚠️ This method to interact with a Telegram bot is about to be depricated and all new API calls will only have their 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)"

Note on requests:

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
}

Contribution

Contributions are welcome!

  1. Fork repository
  2. Do some changes
  3. Create pull request
  4. Wait for CI build and review
  5. ??????
  6. PROFIT

Bear in mind that the CI build won't run integration test suite against your pull request since the necessary environment variables ($BOT_TOKEN, $STRIPE_TOKEN, $CHAT_ID and $BOT_NAME) aren't exported when a fork starts the build (for security reasons). If you do want to run them before creating RP, you can setup integration of your fork with 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 variable
  • PAYMENT_TOKEN is the token obtained from BotFather and must be defined as environment variable
  • CHAT_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 bot
  • HSPEC_ARGS are the normal hspec arguments you can find here

The 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].