Skip to content

Commit

Permalink
Added a new components param (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: Romulo <r_sousa_17@hotmail.com>
Co-authored-by: atymic <atymicq@gmail.com>
  • Loading branch information
3 people committed May 1, 2023
1 parent 71cb781 commit a4ef4fc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -144,6 +144,8 @@ class GameChallengeNotification extends Notification

* `body(string)`: Set the content of the message. ([Supports basic markdown](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-))
* `embed(array)`: Set the embedded content. ([View embed structure](https://discord.com/developers/docs/resources/channel#embed-object))
* `components(array)`: Set the component content. ([View component structure](https://discord.com/developers/docs/interactions/message-components#component-object))


## Changelog

Expand Down
1 change: 1 addition & 0 deletions src/DiscordChannel.php
Expand Up @@ -40,6 +40,7 @@ public function send($notifiable, Notification $notification)
return $this->discord->send($channel, [
'content' => $message->body,
'embed' => $message->embed,
'components' => $message->components
]);
}
}
28 changes: 25 additions & 3 deletions src/DiscordMessage.php
Expand Up @@ -18,25 +18,33 @@ class DiscordMessage
*/
public $embed;

/**
* The component objects attached to the message.
*
* @var array
*/
public $components;

/**
* @param string $body
* @param array|null $embed
*
* @return static
*/
public static function create($body = '', $embed = [])
public static function create($body = '', $embed = [], $components = [])
{
return new static($body, $embed);
return new static($body, $embed, $components);
}

/**
* @param string $body
* @param array $embed
*/
public function __construct($body = '', $embed = [])
public function __construct($body = '', $embed = [], $components = [])
{
$this->body = $body;
$this->embed = $embed;
$this->components = $components;
}

/**
Expand Down Expand Up @@ -66,4 +74,18 @@ public function embed($embed)

return $this;
}

/**
* Set the components object.
*
* @param $components
*
* @return $this
*/
public function components($components)
{
$this->components = $components;

return $this;
}
}
34 changes: 30 additions & 4 deletions tests/DiscordChannelTest.php
Expand Up @@ -21,10 +21,24 @@ public function it_can_send_a_notification()
'headers' => [
'Authorization' => 'Bot super-secret',
],
'json' => ['content' => 'Hello, Discord!', 'embed' => [
'title' => 'Object Title',
'url' => 'https://discord.com',
]],
'json' => [
'content' => 'Hello, Discord!', 'embed' => [
'title' => 'Object Title',
'url' => 'https://discord.com',
], "components" => [
[
"type" => 1,
"components" => [
[
"type" => 2,
"label" => "Test",
"style" => 1,
"custom_id" => "primary"
]
]
]
]
],
])
->andReturn(new Response(200));

Expand Down Expand Up @@ -70,6 +84,18 @@ public function toDiscord()
->embed([
'title' => 'Object Title',
'url' => 'https://discord.com',
])->components([
[
"type" => 1,
"components" => [
[
"type" => 2,
"label" => "Test",
"style" => 1,
"custom_id" => "primary"
]
]
]
]);
}
}

0 comments on commit a4ef4fc

Please sign in to comment.