Webhooks¶
The following section documents everything related to webhooks. Webhooks are currently unavailable in production,
and as such you will need to use https://beta.revolt.chat/api as base API url to use webhooks.
Models¶
BaseWebhook¶
- class stoat.BaseWebhook(*, state, id)[source]¶
Represents a webhook on Stoat.
This inherits from
BaseWebhook.- await delete(*, http_overrides=None, by_token=False)[source]¶
This function is a coroutine.
Deletes the webhook.
Fires
WebhookDeleteEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- await edit(*, http_overrides=None, by_token=False, name=UNDEFINED, avatar=UNDEFINED, permissions=UNDEFINED)[source]¶
This function is a coroutine.
Edits the webhook.
Fires
WebhookUpdateEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.name (UndefinedOr[
str]) – The new webhook name. Must be between 1 and 32 chars long.avatar (UndefinedOr[Optional[
ResolvableResource]]) – The new webhook avatar.permissions (UndefinedOr[
Permissions]) – The new webhook permissions.
- Raises:
HTTPException– Possible values fortype:Value
Reason
FailedValidationThe payload was invalid.
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
by_tokenisTrue.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook/file was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The newly updated webhook.
- Return type:
- await execute(content=None, *, http_overrides=None, nonce=None, attachments=None, replies=None, embeds=None, masquerade=None, interactions=None, silent=None, mention_everyone=None, mention_online=None)[source]¶
This function is a coroutine.
Executes a webhook.
The webhook must have
send_messagesto do this.If message mentions “@everyone” or “@online”, the webhook must have
mention_everyoneto do that.If message mentions any roles, the webhook must have
mention_rolesto do that.Fires
MessageCreateEventand optionallyMessageAppendEvent, both for all users who can see target channel.- Parameters:
webhook (ULIDOr[
BaseWebhook]) – The webhook to execute.token (
str) – The webhook token.content (Optional[
str]) – The message content.http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.nonce (Optional[
str]) – The message nonce.attachments (Optional[List[
ResolvableResource]]) –The attachments to send the message with.
Webhook must have
upload_filesto provide this.replies (Optional[List[Union[
Reply, ULIDOr[BaseMessage]]]]) – The message replies.embeds (Optional[List[
SendableEmbed]]) –The embeds to send the message with.
Webhook must have
send_embedsto provide this.masquerade (Optional[
MessageMasquerade]) –The masquerade for the message.
Webhook must have
use_masqueradeto provide this.If
MessageMasquerade.coloris provided,manage_rolesis also required.interactions (Optional[
MessageInteractions]) –The message interactions.
If
MessageInteractions.reactionsis provided,reactis required.silent (Optional[
bool]) – Whether to suppress notifications or not.mention_everyone (Optional[
bool]) – Whether to mention all users who can see the channel. This cannot be mixed withmention_onlineparameter.mention_online (Optional[
bool]) – Whether to mention all users who are online and can see the channel. This cannot be mixed withmention_everyoneparameter.
- Raises:
HTTPException– Possible values fortype:Value
Reason
EmptyMessageThe message was empty.
FailedValidationThe payload was invalid.
InvalidFlagValueBoth
mention_everyoneandmention_onlinewereTrue.InvalidOperationThe passed nonce was already used. One of
MessageInteractions.reactionselements was invalid.InvalidPropertyMessageInteractions.restrict_reactionswasTruebutMessageInteractions.reactionswas empty.PayloadTooLargeThe message was too large.
TooManyAttachmentsYou provided more attachments than allowed on this instance.
TooManyEmbedsYou provided more embeds than allowed on this instance.
TooManyRepliesYou were replying to more messages than was allowed on this instance.
Unauthorized– Possible values fortype:Value
Reason
NotAuthenticatedThe webhook token is invalid.
Forbidden– Possible values fortype:Value
Reason
MissingPermissionThe webhook do not have the proper permissions to send messages.
NotFound– Possible values fortype:Value
Reason
NotFoundThe channel/file/reply/webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
InternalErrorSomehow something went wrong during message creation.
- Returns:
The message that was sent.
- Return type:
- await fetch(*, http_overrides=None, token=None)[source]¶
This function is a coroutine.
Retrieves a webhook.
If webhook token wasn’t given, the library will attempt get webhook with bot/user token.
You must have
manage_webhooksto do this.Note
Due to Stoat limitation, the webhook avatar information will be partial if no token is provided. Fields are guaranteed to be non-zero/non-empty are
idanduser_id.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.token (Optional[
str]) – The webhook token.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.Forbidden– Possible values fortype:Value
Reason
MissingPermissionYou do not have the proper permissions to retrieve this webhook.
NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The retrieved webhook.
- Return type:
PartialWebhook¶
- class stoat.PartialWebhook(*, state, id, name, internal_avatar, raw_permissions)[source]¶
Represents a partial webhook on Stoat.
Unmodified fields will have
UNDEFINEDas their value.This inherits from
BaseWebhook.- internal_avatar¶
The new webhook’s stateless avatar.
- Type:
UndefinedOr[Optional[
StatelessAsset]]
- property permissions[source]¶
The new webhook’s permissions.
- Type:
UndefinedOr[
Permissions]
- await delete(*, http_overrides=None, by_token=False)[source]¶
This function is a coroutine.
Deletes the webhook.
Fires
WebhookDeleteEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- await edit(*, http_overrides=None, by_token=False, name=UNDEFINED, avatar=UNDEFINED, permissions=UNDEFINED)[source]¶
This function is a coroutine.
Edits the webhook.
Fires
WebhookUpdateEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.name (UndefinedOr[
str]) – The new webhook name. Must be between 1 and 32 chars long.avatar (UndefinedOr[Optional[
ResolvableResource]]) – The new webhook avatar.permissions (UndefinedOr[
Permissions]) – The new webhook permissions.
- Raises:
HTTPException– Possible values fortype:Value
Reason
FailedValidationThe payload was invalid.
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
by_tokenisTrue.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook/file was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The newly updated webhook.
- Return type:
- await execute(content=None, *, http_overrides=None, nonce=None, attachments=None, replies=None, embeds=None, masquerade=None, interactions=None, silent=None, mention_everyone=None, mention_online=None)[source]¶
This function is a coroutine.
Executes a webhook.
The webhook must have
send_messagesto do this.If message mentions “@everyone” or “@online”, the webhook must have
mention_everyoneto do that.If message mentions any roles, the webhook must have
mention_rolesto do that.Fires
MessageCreateEventand optionallyMessageAppendEvent, both for all users who can see target channel.- Parameters:
webhook (ULIDOr[
BaseWebhook]) – The webhook to execute.token (
str) – The webhook token.content (Optional[
str]) – The message content.http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.nonce (Optional[
str]) – The message nonce.attachments (Optional[List[
ResolvableResource]]) –The attachments to send the message with.
Webhook must have
upload_filesto provide this.replies (Optional[List[Union[
Reply, ULIDOr[BaseMessage]]]]) – The message replies.embeds (Optional[List[
SendableEmbed]]) –The embeds to send the message with.
Webhook must have
send_embedsto provide this.masquerade (Optional[
MessageMasquerade]) –The masquerade for the message.
Webhook must have
use_masqueradeto provide this.If
MessageMasquerade.coloris provided,manage_rolesis also required.interactions (Optional[
MessageInteractions]) –The message interactions.
If
MessageInteractions.reactionsis provided,reactis required.silent (Optional[
bool]) – Whether to suppress notifications or not.mention_everyone (Optional[
bool]) – Whether to mention all users who can see the channel. This cannot be mixed withmention_onlineparameter.mention_online (Optional[
bool]) – Whether to mention all users who are online and can see the channel. This cannot be mixed withmention_everyoneparameter.
- Raises:
HTTPException– Possible values fortype:Value
Reason
EmptyMessageThe message was empty.
FailedValidationThe payload was invalid.
InvalidFlagValueBoth
mention_everyoneandmention_onlinewereTrue.InvalidOperationThe passed nonce was already used. One of
MessageInteractions.reactionselements was invalid.InvalidPropertyMessageInteractions.restrict_reactionswasTruebutMessageInteractions.reactionswas empty.PayloadTooLargeThe message was too large.
TooManyAttachmentsYou provided more attachments than allowed on this instance.
TooManyEmbedsYou provided more embeds than allowed on this instance.
TooManyRepliesYou were replying to more messages than was allowed on this instance.
Unauthorized– Possible values fortype:Value
Reason
NotAuthenticatedThe webhook token is invalid.
Forbidden– Possible values fortype:Value
Reason
MissingPermissionThe webhook do not have the proper permissions to send messages.
NotFound– Possible values fortype:Value
Reason
NotFoundThe channel/file/reply/webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
InternalErrorSomehow something went wrong during message creation.
- Returns:
The message that was sent.
- Return type:
- await fetch(*, http_overrides=None, token=None)[source]¶
This function is a coroutine.
Retrieves a webhook.
If webhook token wasn’t given, the library will attempt get webhook with bot/user token.
You must have
manage_webhooksto do this.Note
Due to Stoat limitation, the webhook avatar information will be partial if no token is provided. Fields are guaranteed to be non-zero/non-empty are
idanduser_id.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.token (Optional[
str]) – The webhook token.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.Forbidden– Possible values fortype:Value
Reason
MissingPermissionYou do not have the proper permissions to retrieve this webhook.
NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The retrieved webhook.
- Return type:
Webhook¶
- async delete
- async edit
- async execute
- async fetch
- def get_channel
- def get_creator
- def get_creator_as_member
- def get_creator_as_user
- def locally_update
- def to_dict
- class stoat.Webhook(*, state, id, name, internal_avatar, creator_id, channel_id, raw_permissions, token)[source]¶
Represents a webhook on Stoat.
This inherits from
BaseWebhook.- internal_avatar¶
The webhook’s stateless avatar.
- Type:
Optional[
StatelessAsset]
- creator_id¶
The user’s ID who created this webhook.
Warning
This is available only since API v0.7.17 and only not from
GET /webhooks/{webhook.id}endpoints. The attribute will be empty string if unavailable.- Type:
- get_channel()[source]¶
Optional[Union[
GroupChannel,TextChannel]]: The channel the webhook belongs to.
- await delete(*, http_overrides=None, by_token=False)[source]¶
This function is a coroutine.
Deletes the webhook.
Fires
WebhookDeleteEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- await edit(*, http_overrides=None, by_token=False, name=UNDEFINED, avatar=UNDEFINED, permissions=UNDEFINED)[source]¶
This function is a coroutine.
Edits the webhook.
Fires
WebhookUpdateEventfor all users who can see webhook channel.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.by_token (
bool) –Whether to use webhook token, if possible.
You must have
manage_webhooksto provideFalse.name (UndefinedOr[
str]) – The new webhook name. Must be between 1 and 32 chars long.avatar (UndefinedOr[Optional[
ResolvableResource]]) – The new webhook avatar.permissions (UndefinedOr[
Permissions]) – The new webhook permissions.
- Raises:
HTTPException– Possible values fortype:Value
Reason
FailedValidationThe payload was invalid.
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
by_tokenisTrue.NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook/file was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The newly updated webhook.
- Return type:
- await execute(content=None, *, http_overrides=None, nonce=None, attachments=None, replies=None, embeds=None, masquerade=None, interactions=None, silent=None, mention_everyone=None, mention_online=None)[source]¶
This function is a coroutine.
Executes a webhook.
The webhook must have
send_messagesto do this.If message mentions “@everyone” or “@online”, the webhook must have
mention_everyoneto do that.If message mentions any roles, the webhook must have
mention_rolesto do that.Fires
MessageCreateEventand optionallyMessageAppendEvent, both for all users who can see target channel.- Parameters:
webhook (ULIDOr[
BaseWebhook]) – The webhook to execute.token (
str) – The webhook token.content (Optional[
str]) – The message content.http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.nonce (Optional[
str]) – The message nonce.attachments (Optional[List[
ResolvableResource]]) –The attachments to send the message with.
Webhook must have
upload_filesto provide this.replies (Optional[List[Union[
Reply, ULIDOr[BaseMessage]]]]) – The message replies.embeds (Optional[List[
SendableEmbed]]) –The embeds to send the message with.
Webhook must have
send_embedsto provide this.masquerade (Optional[
MessageMasquerade]) –The masquerade for the message.
Webhook must have
use_masqueradeto provide this.If
MessageMasquerade.coloris provided,manage_rolesis also required.interactions (Optional[
MessageInteractions]) –The message interactions.
If
MessageInteractions.reactionsis provided,reactis required.silent (Optional[
bool]) – Whether to suppress notifications or not.mention_everyone (Optional[
bool]) – Whether to mention all users who can see the channel. This cannot be mixed withmention_onlineparameter.mention_online (Optional[
bool]) – Whether to mention all users who are online and can see the channel. This cannot be mixed withmention_everyoneparameter.
- Raises:
HTTPException– Possible values fortype:Value
Reason
EmptyMessageThe message was empty.
FailedValidationThe payload was invalid.
InvalidFlagValueBoth
mention_everyoneandmention_onlinewereTrue.InvalidOperationThe passed nonce was already used. One of
MessageInteractions.reactionselements was invalid.InvalidPropertyMessageInteractions.restrict_reactionswasTruebutMessageInteractions.reactionswas empty.PayloadTooLargeThe message was too large.
TooManyAttachmentsYou provided more attachments than allowed on this instance.
TooManyEmbedsYou provided more embeds than allowed on this instance.
TooManyRepliesYou were replying to more messages than was allowed on this instance.
Unauthorized– Possible values fortype:Value
Reason
NotAuthenticatedThe webhook token is invalid.
Forbidden– Possible values fortype:Value
Reason
MissingPermissionThe webhook do not have the proper permissions to send messages.
NotFound– Possible values fortype:Value
Reason
NotFoundThe channel/file/reply/webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
InternalErrorSomehow something went wrong during message creation.
- Returns:
The message that was sent.
- Return type:
- await fetch(*, http_overrides=None, token=None)[source]¶
This function is a coroutine.
Retrieves a webhook.
If webhook token wasn’t given, the library will attempt get webhook with bot/user token.
You must have
manage_webhooksto do this.Note
Due to Stoat limitation, the webhook avatar information will be partial if no token is provided. Fields are guaranteed to be non-zero/non-empty are
idanduser_id.- Parameters:
http_overrides (Optional[
HTTPOverrideOptions]) – The HTTP request overrides.token (Optional[
str]) – The webhook token.
- Raises:
Unauthorized– Possible values fortype:Value
Reason
InvalidSessionThe current bot/user token is invalid.
NotAuthenticatedThe webhook token is invalid. Only applicable when
tokenis provided.Forbidden– Possible values fortype:Value
Reason
MissingPermissionYou do not have the proper permissions to retrieve this webhook.
NotFound– Possible values fortype:Value
Reason
NotFoundThe webhook was not found.
InternalServerError– Possible values fortype:Value
Reason
Populated attributes
DatabaseErrorSomething went wrong during querying database.
- Returns:
The retrieved webhook.
- Return type:
- locally_update(data, /)[source]¶
Locally updates webhook with provided data.
Warning
This is called by library internally to keep cache up to date.
- Parameters:
data (
PartialWebhook) – The data to update webhook with.
- property channel[source]¶
The channel the webhook belongs to.
- Type:
Union[
GroupChannel,TextChannel]