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

Search
Loading...
Searching...
No Matches
dpp::webhook Class Reference

Represents a discord webhook. More...

`#include <webhook.h>`

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

## Public Member Functions

| webhook ()
| Construct a new webhook object.
| webhook (const snowflake webhook_id, const std::string &webhook_token)
| Construct a new webhook object using the webhook ID and the webhook token.
| webhook (const std::string &webhook_url)
| Construct a new webhook object using the Webhook URL provided by Discord.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
webhook & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
constexpr double | get_creation_time () const noexcept
| Get the creation time of this object according to Discord.
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.
constexpr bool | operator!= (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
constexpr bool | operator== (const managed &other) const noexcept
| Comparison operator for comparing two managed objects by id.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.

## Public Attributes

snowflake | application_id
| The bot/OAuth2 application that created this webhook.
utility::iconhash | avatar
| The default avatar of the webhook.
std::string | avatar_url
| Avatar URL to use instead of the default if it is set.
snowflake | channel_id
| The channel id this webhook is for.
snowflake | guild_id
| The guild id this webhook is for.
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.
std::string | image_data
| base64 encoded image data if uploading a new image.
std::string | name
| The default name of the webhook.
channel | source_channel
| The channel that this webhook is following (only for Channel Follower Webhooks).
guild | source_guild
| The guild of the channel that this webhook is following (only for Channel Follower Webhooks).
std::string | token
| The secure token of the webhook (returned for Incoming Webhooks).
uint8_t | type
| Type of the webhook from dpp::webhook_type.
std::string | url
| The url used for executing the webhook (returned by the webhooks OAuth2 flow).
user | user_obj
| The user this webhook was created by.

## Protected Member Functions

webhook & | fill_from_json_impl (nlohmann::json *j)
| Fill in object from json data.
virtual json | to_json_impl (bool with_id=false) const
| Build JSON string from object.

## 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_url | a fully qualified web address of an existing webhook

Exceptions

  logic_exception | if 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_id | id taken from a link of an existing webhook
  webhook_token | token 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

inline inherited

Convert object to json string.

Parameters

  with_id | Whether 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 | ) |

inline inherited

Convert object from nlohmann::json.

Parameters

  j | nlohmann::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

  j | JSON data

Returns
  webhook& Reference to self

## ◆ get_creation_time()

double dpp::managed::get_creation_time | ( |  | ) | const

inline constexpr noexcept inherited

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_blob | Binary image data
  type | Image type. It can be one of i_gif, i_jpg or i_png.
  is_base64_encoded | True if the image data is already base64 encoded

Returns
  webhook& Reference to self

Exceptions

  dpp::length_exception | Image data is larger than the maximum size of 256 kilobytes

## ◆ operator!=()

bool dpp::managed::operator!= | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other object to compare against

Returns
  true objects are not the same id
  false objects are the same id

## ◆ operator==()

bool dpp::managed::operator== | ( | const managed & | other | ) | const

inline constexpr noexcept inherited

Comparison operator for comparing two managed objects by id.

Parameters

  other | Other 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

inline inherited

Convert object to nlohmann::json.

Parameters

  with_id | Whether 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

protected virtual

Build JSON string from object.

Parameters

  with_id | Include the ID of the webhook in the json

Returns
  std::string JSON encoded object

## Friends And Related Symbol 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 value will not have any effect when avatar_url is set, they are mutually exclusive.
  This may be empty.

## ◆ avatar_url

std::string dpp::webhook::avatar_url

Avatar URL to use instead of the default if it is set.

Note
  This will override avatar if it is set, they are mutually exclusive.
  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.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