| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::discord_webhook_server Struct Reference

Creates a HTTP server which listens for incoming Discord interactions, and if verified as valid, raises them as cluster events, returning the response back. Note that Discord requires all interaction endpoints to have a valid SSL certificate (not self signed) so in most cases you should put this port behind a reverse proxy, e.g. nginx, apache, etc. More...

`#include <discord_webhook_server.h>`

Inheritance diagram for dpp::discord_webhook_server:
[legend]
Collaboration diagram for dpp::discord_webhook_server:
[legend]

## Public Member Functions

| discord_webhook_server (cluster *creator, const std::string &discord_public_key, const std::string_view address, uint16_t port, const std::string &ssl_private_key="", const std::string &ssl_public_key="")
| Constructor for creation of a HTTP(S) server.
virtual | ~discord_webhook_server ()=default
| Virtual dtor.
void | emplace (socket newfd) override
| Emplace a new request into the connection pool.
virtual void | handle_accept (socket sfd, const struct socket_events &e)
| Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.
void | handle_request (http_server_request *request)
| Handle Discord outbound webhook.

## Public Attributes

uint16_t | bound_port
| Port we are listening on.
event_handle | close_event
| Event to handle socket removal from the connection map.
std::unordered_map< socket, std::unique_ptr< http_server_request > > | connections
| Active connections for the server of type T.
cluster * | creator
| Cluster creator.
socket_events | events
| Socket events for listen socket in the socket engine.
raii_socket | fd
| The listening socket for incoming connections.
bool | plaintext
| True if plain text connections to the server are allowed.
std::string | private_key_file
| Private key PEM file path, if running an SSL server.
std::string | public_key_file
| Public key PEM file path, if running an SSL server.
std::string | public_key_hex
| Public key from application dashboard.
http_server_request_event | request_handler
| Request handler callback to use for all incoming HTTP(S) requests.
signature_verifier | verifier
| Verifier for signed requests.

## Detailed Description

Creates a HTTP server which listens for incoming Discord interactions, and if verified as valid, raises them as cluster events, returning the response back. Note that Discord requires all interaction endpoints to have a valid SSL certificate (not self signed) so in most cases you should put this port behind a reverse proxy, e.g. nginx, apache, etc.

## Constructor & Destructor Documentation

## ◆ discord_webhook_server()

dpp::discord_webhook_server::discord_webhook_server | ( | cluster * | creator,
|  | const std::string & | discord_public_key,
|  | const std::string_view | address,
|  | uint16_t | port,
|  | const std::string & | ssl_private_key = "",
|  | const std::string & | ssl_public_key = "" )

Constructor for creation of a HTTP(S) server.

Parameters

  creator | Cluster creator
  discord_public_key | Public key for the application from the application dashboard page
  address | address to bind to, use "0.0.0.0" to bind to all local addresses
  port | port to bind to. You should generally use a port > 1024.
  ssl_private_key | Private key PEM file for HTTPS/SSL. If empty, a plaintext server is created
  ssl_public_key | Public key PEM file for HTTPS/SSL. If empty, a plaintext server is created

## ◆ ~discord_webhook_server()

virtual dpp::discord_webhook_server::~discord_webhook_server | ( |  | ) |

virtual default

Virtual dtor.

## Member Function Documentation

## ◆ emplace()

void dpp::http_server::emplace | ( | socket | newfd | ) |

override virtual inherited

Emplace a new request into the connection pool.

Parameters

  newfd | file descriptor of new request

Implements dpp::socket_listener< http_server_request >.

## ◆ handle_accept()

virtual void dpp::socket_listener< http_server_request, typename >::handle_accept | ( | socket | sfd,
|  | const struct socket_events & | e )

inline virtual inherited

Handle a new incoming socket with accept() Accepts a new connection, and calls emplace() if valid.

Parameters

  sfd | File descriptor for listening socket
  e | socket events for the listening socket

## ◆ handle_request()

void dpp::discord_webhook_server::handle_request | ( | http_server_request * | request | ) |

Handle Discord outbound webhook.

Parameters

  request | Request from discord

## Member Data Documentation

## ◆ bound_port

uint16_t dpp::http_server::bound_port

inherited

Port we are listening on.

## ◆ close_event

event_handle dpp::socket_listener< http_server_request, typename >::close_event

inherited

Event to handle socket removal from the connection map.

## ◆ connections

std::unordered_map<socket, std::unique_ptr<http_server_request> > dpp::socket_listener< http_server_request, typename >::connections

inherited

Active connections for the server of type T.

## ◆ creator

cluster* dpp::socket_listener< http_server_request, typename >::creator

inherited

Cluster creator.

## ◆ events

socket_events dpp::socket_listener< http_server_request, typename >::events

inherited

Socket events for listen socket in the socket engine.

## ◆ fd

raii_socket dpp::socket_listener< http_server_request, typename >::fd

inherited

The listening socket for incoming connections.

## ◆ plaintext

bool dpp::socket_listener< http_server_request, typename >::plaintext

inherited

True if plain text connections to the server are allowed.

## ◆ private_key_file

std::string dpp::socket_listener< http_server_request, typename >::private_key_file

inherited

Private key PEM file path, if running an SSL server.

## ◆ public_key_file

std::string dpp::socket_listener< http_server_request, typename >::public_key_file

inherited

Public key PEM file path, if running an SSL server.

## ◆ public_key_hex

std::string dpp::discord_webhook_server::public_key_hex

Public key from application dashboard.

## ◆ request_handler

http_server_request_event dpp::http_server::request_handler

inherited

Request handler callback to use for all incoming HTTP(S) requests.

## ◆ verifier

signature_verifier dpp::discord_webhook_server::verifier

Verifier for signed requests.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0