cpr-based connectors#

Available connectors

blocking

cpr_blocking, cpr_blocking_monadic

async

cpr_async

coroutine

Connector implemented on top of cpr library. Link with banana-cpr to use it.

You can also pass BANANA_USE_BUNDLED_CPR=ON CMake flag to use bundled cpr library (CMake will automatically download and link it to banana-cpr target). However, it requires OpenSSL installed on your machine.

CMake Target

banana-cpr

Include

#include <banana/connector/cpr.hpp>

Supported platforms

Windows, Linux, macOS

Dependencies

cpr, OpenSSL

class cpr_blocking#

cpr-based blocking connector with exception-based error handling.

cpr_blocking::cpr_blocking(std::string token)#

Default constructor accepting Telegram Bot token.

template<class T>
T request(std::string_view method, std::optional<std::string> body, expected<T> (*then)(expected<std::string>))#

Part of the required connector interface.

Example
#include <banana/connector/cpr.hpp>

banana::connector::cpr_blocking connector("TG_BOT_TOKEN");
banana::api::message_t msg = banana::api::send_message(connector, { "@user", "Hello, world!" });

class cpr_blocking_monadic#

cpr-based blocking connector with monadic error handling.

cpr_blocking_monadic::cpr_blocking_monadic(std::string token)#

Default constructor accepting Telegram Bot token.

template<class T>
expected<T> request(std::string_view method, std::optional<std::string> body, expected<T> (*then)(expected<std::string>))#

Part of the required connector interface.

Example
#include <banana/connector/cpr.hpp>

banana::connector::cpr_blocking_monadic connector("TG_BOT_TOKEN");
banana::expected<banana::api::message_t> msg = banana::api::send_message(connector, { "@user", "Hello, world!" });

class cpr_async#

cpr-based non-blocking connector that wraps all requests in std::async.

cpr_async::cpr_async(std::string token)#

Default constructor accepting Telegram Bot token.

template<class T>
std::future<T> request(std::string_view method, std::optional<std::string> body, expected<T> (*then)(expected<std::string>))#

Part of the required connector interface.

Example
#include <banana/connector/cpr.hpp>

banana::connector::cpr_async connector("TG_BOT_TOKEN");
std::future<banana::api::message_t> msg = banana::api::send_message(connector, { "@user", "Hello, world!" });