Skip to content

Commit a4ef4fc

Browse files
romulosalmeidaRomuloalmeidaatymic
authored
Added a new components param (#65)
Co-authored-by: Romulo <[email protected]> Co-authored-by: atymic <[email protected]>
1 parent 71cb781 commit a4ef4fc

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class GameChallengeNotification extends Notification
144144

145145
* `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-))
146146
* `embed(array)`: Set the embedded content. ([View embed structure](https://discord.com/developers/docs/resources/channel#embed-object))
147+
* `components(array)`: Set the component content. ([View component structure](https://discord.com/developers/docs/interactions/message-components#component-object))
148+
147149

148150
## Changelog
149151

src/DiscordChannel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function send($notifiable, Notification $notification)
4040
return $this->discord->send($channel, [
4141
'content' => $message->body,
4242
'embed' => $message->embed,
43+
'components' => $message->components
4344
]);
4445
}
4546
}

src/DiscordMessage.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,33 @@ class DiscordMessage
1818
*/
1919
public $embed;
2020

21+
/**
22+
* The component objects attached to the message.
23+
*
24+
* @var array
25+
*/
26+
public $components;
27+
2128
/**
2229
* @param string $body
2330
* @param array|null $embed
2431
*
2532
* @return static
2633
*/
27-
public static function create($body = '', $embed = [])
34+
public static function create($body = '', $embed = [], $components = [])
2835
{
29-
return new static($body, $embed);
36+
return new static($body, $embed, $components);
3037
}
3138

3239
/**
3340
* @param string $body
3441
* @param array $embed
3542
*/
36-
public function __construct($body = '', $embed = [])
43+
public function __construct($body = '', $embed = [], $components = [])
3744
{
3845
$this->body = $body;
3946
$this->embed = $embed;
47+
$this->components = $components;
4048
}
4149

4250
/**
@@ -66,4 +74,18 @@ public function embed($embed)
6674

6775
return $this;
6876
}
77+
78+
/**
79+
* Set the components object.
80+
*
81+
* @param $components
82+
*
83+
* @return $this
84+
*/
85+
public function components($components)
86+
{
87+
$this->components = $components;
88+
89+
return $this;
90+
}
6991
}

tests/DiscordChannelTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@ public function it_can_send_a_notification()
2121
'headers' => [
2222
'Authorization' => 'Bot super-secret',
2323
],
24-
'json' => ['content' => 'Hello, Discord!', 'embed' => [
25-
'title' => 'Object Title',
26-
'url' => 'https://discord.com',
27-
]],
24+
'json' => [
25+
'content' => 'Hello, Discord!', 'embed' => [
26+
'title' => 'Object Title',
27+
'url' => 'https://discord.com',
28+
], "components" => [
29+
[
30+
"type" => 1,
31+
"components" => [
32+
[
33+
"type" => 2,
34+
"label" => "Test",
35+
"style" => 1,
36+
"custom_id" => "primary"
37+
]
38+
]
39+
]
40+
]
41+
],
2842
])
2943
->andReturn(new Response(200));
3044

@@ -70,6 +84,18 @@ public function toDiscord()
7084
->embed([
7185
'title' => 'Object Title',
7286
'url' => 'https://discord.com',
87+
])->components([
88+
[
89+
"type" => 1,
90+
"components" => [
91+
[
92+
"type" => 2,
93+
"label" => "Test",
94+
"style" => 1,
95+
"custom_id" => "primary"
96+
]
97+
]
98+
]
7399
]);
74100
}
75101
}

0 commit comments

Comments
 (0)