D++ (DPP)
C++ Discord API Bot Library
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:
+ Collaboration diagram for dpp::discord_webhook_server:

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. More...
 
void handle_request (http_server_request *request)
 Handle Discord outbound webhook. More...
 
virtual ~discord_webhook_server ()=default
 Virtual dtor. More...
 
void emplace (socket newfd) override
 Emplace a new request into the connection pool. More...
 
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. More...
 

Public Attributes

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

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
creatorCluster creator
discord_public_keyPublic key for the application from the application dashboard page
addressaddress to bind to, use "0.0.0.0" to bind to all local addresses
portport to bind to. You should generally use a port > 1024.
ssl_private_keyPrivate key PEM file for HTTPS/SSL. If empty, a plaintext server is created
ssl_public_keyPublic key PEM file for HTTPS/SSL. If empty, a plaintext server is created

◆ ~discord_webhook_server()

virtual dpp::discord_webhook_server::~discord_webhook_server ( )
virtualdefault

Virtual dtor.

Member Function Documentation

◆ emplace()

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

Emplace a new request into the connection pool.

Parameters
newfdfile 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 
)
inlinevirtualinherited

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

Parameters
sfdFile descriptor for listening socket
esocket events for the listening socket

◆ handle_request()

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

Handle Discord outbound webhook.

Parameters
requestRequest 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

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 10.1.1D++ Library version 10.1.0D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0