sn0wyQ / SQBot

C++20 Library for Telegram Bot API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CI Checks

SQBot

C++20 Library for Telegram Bot API

Hello, World!

Bot that sends "Hello, World!" to anyone who sends him /hello command:

#include <iostream>

#include "SQBot/Bot/bot.h"
#include "SQBot/EventManager/event_manager.h"

int main() {
  SQBot::Bot bot("YOUR_TOKEN_HERE");

  bot.GetEventManager()->SetCallbackForMessageFirstWordIs("/hello",
     [](SQBot::Bot* bot, const MessagePtr& message) {
       bot->SendMessage(message->chat->id,
                        "Hello, World!");
     });

  bot.StartReceivingUpdates();

  return 0;
}

You can also use your own functions instead of lambdas:

void GreetTheWorld(SQBot::Bot* bot, const MessagePtr& message) {
  bot->SendMessage(message->chat->id, "Hello, World!");
}

// ...

bot.GetEventManager()->SetCallbackForMessageFirstWordIs("/hello", GreetTheWorld);

Dependencies

You need CURL and nlohmann json

About

C++20 Library for Telegram Bot API


Languages

Language:C++ 99.7%Language:CMake 0.2%Language:C 0.0%