Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Latest commit

 

History

History
59 lines (43 loc) · 2.02 KB

Payload.md

File metadata and controls

59 lines (43 loc) · 2.02 KB

Payload

The Payload class implement PayloadInterface, which in turn inherits from two interfaces: SetPayloadInterface and GetPayloadInterface

WebhookClient::send requires only an object of the GetPayloadInterface type as an argument, which means that you can omit the entire Payload class and define your own templates, which will, like the Payload class, return all components required for Payload in the GetPayloadInterface::toArray method

The Payload class, thanks to the SetPayloadInterface implementation, offers the following methods:

  • setUsername - to set webhook bot name
  • setAvatarUrl - set webhook bot avatar
  • setMessage - to set a text message
  • setEmbed - to add embed
  • setTts - to set or unset TTS

All setters implement the Fluent Interface pattern.

Examples

Only embed

$payload = new Payload();
$payload->addEmbed($embed) // @see Embed.md
;

If you want change avatar or username then

$payload = new Payload();
$payload->setAvatarUrl("Webhook Bot Avatar URL")
    ->setUsername("Webhook Bot Name")
;

If you need send some text before embed then use

$payload = new Payload();
$payload->setMessage("Some message")
    ->addEmbed($embed) // @see Embed.md
;

With all setters

$payload = new Payload();
$payload->setAvatarUrl("Webhook Bot Avatar URL")
    ->setUsername("Webhook Bot Name")
    ->setMessage("Some message")
    ->setTts(false) // or true.. if you want it
    ->addEmbed($embed) // @see Embed.md
;