D++ (DPP)
C++ Discord API Bot Library
dpp::webhook Class Reference

Represents a discord webhook. More...

+ Inheritance diagram for dpp::webhook:
+ Collaboration diagram for dpp::webhook:

Public Member Functions

 webhook ()
 Construct a new webhook object. More...
 
 webhook (const std::string &webhook_url)
 Construct a new webhook object using the Webhook URL provided by Discord. More...
 
 webhook (const snowflake webhook_id, const std::string &webhook_token)
 Construct a new webhook object using the webhook ID and the webhook token. More...
 
webhookload_image (const std::string &image_blob, const image_type type, bool is_base64_encoded=false)
 Base64 encode image data and allocate it to image_data. More...
 
constexpr double get_creation_time () const noexcept
 Get the creation time of this object according to Discord. More...
 
constexpr bool operator== (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
constexpr bool operator!= (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
webhookfill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 

Public Attributes

uint8_t type
 Type of the webhook from dpp::webhook_type. More...
 
snowflake guild_id
 The guild id this webhook is for. More...
 
snowflake channel_id
 The channel id this webhook is for. More...
 
user user_obj
 The user this webhook was created by. More...
 
std::string name
 The default name of the webhook. More...
 
utility::iconhash avatar
 The default avatar of the webhook. More...
 
std::string token
 The secure token of the webhook (returned for Incoming Webhooks). More...
 
snowflake application_id
 The bot/OAuth2 application that created this webhook. More...
 
guild source_guild
 The guild of the channel that this webhook is following (only for Channel Follower Webhooks). More...
 
channel source_channel
 The channel that this webhook is following (only for Channel Follower Webhooks). More...
 
std::string url
 The url used for executing the webhook (returned by the webhooks OAuth2 flow). More...
 
std::string image_data
 base64 encoded image data if uploading a new image. More...
 
snowflake id = {}
 Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata. More...
 

Protected Member Functions

webhookfill_from_json_impl (nlohmann::json *j)
 Fill in object from json data. More...
 
virtual json to_json_impl (bool with_id=false) const
 Build JSON string from object. More...
 

Friends

struct json_interface< webhook >
 

Detailed Description

Represents a discord webhook.

Constructor & Destructor Documentation

◆ webhook() [1/3]

dpp::webhook::webhook ( )

Construct a new webhook object.

◆ webhook() [2/3]

dpp::webhook::webhook ( const std::string &  webhook_url)

Construct a new webhook object using the Webhook URL provided by Discord.

Parameters
webhook_urla fully qualified web address of an existing webhook
Exceptions
logic_exceptionif the webhook url could not be parsed

◆ webhook() [3/3]

dpp::webhook::webhook ( const snowflake  webhook_id,
const std::string &  webhook_token 
)

Construct a new webhook object using the webhook ID and the webhook token.

Parameters
webhook_idid taken from a link of an existing webhook
webhook_tokentoken taken from a link of an existing webhook

Member Function Documentation

◆ build_json()

std::string dpp::json_interface< webhook >::build_json ( bool  with_id = false) const
inlineinherited

Convert object to json string.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
std::string Json built from the structure

◆ fill_from_json()

webhook & dpp::json_interface< webhook >::fill_from_json ( nlohmann::json *  j)
inlineinherited

Convert object from nlohmann::json.

Parameters
jnlohmann::json object
Returns
T& Reference to self for fluent calling

◆ fill_from_json_impl()

webhook& dpp::webhook::fill_from_json_impl ( nlohmann::json *  j)
protected

Fill in object from json data.

Parameters
jJSON data
Returns
webhook& Reference to self

◆ get_creation_time()

constexpr double dpp::managed::get_creation_time ( ) const
inlineconstexprnoexceptinherited

Get the creation time of this object according to Discord.

Returns
double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

◆ load_image()

webhook& dpp::webhook::load_image ( const std::string &  image_blob,
const image_type  type,
bool  is_base64_encoded = false 
)

Base64 encode image data and allocate it to image_data.

Parameters
image_blobBinary image data
typeImage type. It can be one of i_gif, i_jpg or i_png.
is_base64_encodedTrue if the image data is already base64 encoded
Returns
webhook& Reference to self
Exceptions
dpp::length_exceptionImage data is larger than the maximum size of 256 kilobytes

◆ operator!=()

constexpr bool dpp::managed::operator!= ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are not the same id
false objects are the same id

◆ operator==()

constexpr bool dpp::managed::operator== ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are the same id
false objects are not the same id

◆ to_json()

auto dpp::json_interface< webhook >::to_json ( bool  with_id = false) const
inlineinherited

Convert object to nlohmann::json.

Parameters
with_idWhether to include the ID or not
Note
Some fields are conditionally filled, do not rely on all fields being present
Returns
json Json built from the structure

◆ to_json_impl()

virtual json dpp::webhook::to_json_impl ( bool  with_id = false) const
protectedvirtual

Build JSON string from object.

Parameters
with_idInclude the ID of the webhook in the json
Returns
std::string JSON encoded object

Friends And Related Function Documentation

◆ json_interface< webhook >

friend struct json_interface< webhook >
friend

Member Data Documentation

◆ application_id

snowflake dpp::webhook::application_id

The bot/OAuth2 application that created this webhook.

Note
This may be empty.

◆ avatar

utility::iconhash dpp::webhook::avatar

The default avatar of the webhook.

Note
This may be empty.

◆ channel_id

snowflake dpp::webhook::channel_id

The channel id this webhook is for.

Note
This may be empty.

◆ guild_id

snowflake dpp::webhook::guild_id

The guild id this webhook is for.

Note
This field is optional, and may also be empty.

◆ id

snowflake dpp::managed::id = {}
inherited

Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.

◆ image_data

std::string dpp::webhook::image_data

base64 encoded image data if uploading a new image.

Warning
You should only ever read data from here. If you want to set the data, use dpp::webhook::load_image.

◆ name

std::string dpp::webhook::name

The default name of the webhook.

Note
This may be empty.

◆ source_channel

channel dpp::webhook::source_channel

The channel that this webhook is following (only for Channel Follower Webhooks).

Warning
This will be absent if the webhook creator has since lost access to the guild where the followed channel resides!

◆ source_guild

guild dpp::webhook::source_guild

The guild of the channel that this webhook is following (only for Channel Follower Webhooks).

Warning
This will be absent if the webhook creator has since lost access to the guild where the followed channel resides!

◆ token

std::string dpp::webhook::token

The secure token of the webhook (returned for Incoming Webhooks).

Note
This field is optional.

◆ type

uint8_t dpp::webhook::type

Type of the webhook from dpp::webhook_type.

◆ url

std::string dpp::webhook::url

The url used for executing the webhook (returned by the webhooks OAuth2 flow).

◆ user_obj

user dpp::webhook::user_obj

The user this webhook was created by.

Note
This field is optional.
Warning
This is not returned when getting a webhook with its token!
D++ 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