diff --git a/src/Extensions/ElementButton.php b/src/Extensions/ElementButton.php index 9f40449..7e3a5ac 100644 --- a/src/Extensions/ElementButton.php +++ b/src/Extensions/ElementButton.php @@ -184,7 +184,7 @@ public function toArray() $buttonArray['fallback_url'] = $this->fallback_url ?: $this->url; } } - } elseif ($this->type == self::TYPE_SHARE) { + } elseif ($this->type == self::TYPE_SHARE && !is_null($this->shareContents)) { $buttonArray['share_contents'] = $this->shareContents->toArray(); } diff --git a/tests/Extensions/ElementButtonTest.php b/tests/Extensions/ElementButtonTest.php index 078a648..c55f486 100644 --- a/tests/Extensions/ElementButtonTest.php +++ b/tests/Extensions/ElementButtonTest.php @@ -148,4 +148,20 @@ public function it_can_set_share_contents() $this->assertSame($share->toArray(), Arr::get($button->toArray(), 'share_contents')); } + + /** + * @test + **/ + public function it_can_share_contents_with_manual_assigned_buttons() + { + $share = ElementButton::create('Share') + ->type(ElementButton::TYPE_SHARE) + ->url('https://botman.io'); + + $payload = [ + 'type' => 'element_share', + ]; + + $this->assertSame($share->toArray(), $payload); + } }