-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from massimo-filippi/develop
Develop
- Loading branch information
Showing
11 changed files
with
970 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Things to do... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
return [ | ||
'massimo_filippi' => [ | ||
'slack_module' => [ | ||
'webhook_url' => 'https://hooks.slack.com/services/#########/#########/########################', | ||
// Whether names like @regan should be converted into links by Slack, default: false | ||
'link_names' => false, | ||
// Whether Slack should unfurl links to text-based content, default: false | ||
'unfurl_links' => false, | ||
// Whether Slack should unfurl links to media content such as images and YouTube videos, default: true | ||
'unfurl_media' => true, | ||
// Whether message text should be interpreted in Slack's Markdown-like language. For formatting options, see Slack's help article: http://goo.gl/r4fsdO, default: true | ||
'allow_markdown' => true, | ||
// Which attachment fields should be interpreted in Slack's Markdown-like language. By default, Slack assumes that no fields in an attachment should be formatted as Markdown. // default: [] | ||
'markdown_in_attachments' => [], | ||
|
||
// Allow Markdown in just the text and title fields | ||
//// 'markdown_in_attachments' => ['text', 'title'] | ||
// Allow Markdown in all fields | ||
//// 'markdown_in_attachments' => ['pretext', 'text', 'title', 'fields', 'fallback'] | ||
|
||
'defaults' => [ | ||
// default username, set to null to use the default set on the Slack webhook, default: null | ||
'username' => 'Slack module', | ||
// default channel, channel: #general, user: @john.doe, set to null to use the default set on the Slack webhook, default: null | ||
'channel' => '#general', | ||
// URL to an image or Slack emoji like :ghost: or :+1:, set null to use the default set on the Slack webhook, default: null | ||
'icon' => null | ||
], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
namespace MassimoFilippi\SlackModule\Model; | ||
|
||
/** | ||
* Class Attachment | ||
* @package MassimoFilippi\SlackModule\Model | ||
*/ | ||
class Attachment extends \Maknz\Slack\Attachment | ||
{ | ||
/** | ||
* The actions of the attachment | ||
* | ||
* @var array | ||
*/ | ||
protected $actions = []; | ||
|
||
/** | ||
* Attachment constructor. | ||
* @param array $attributes | ||
*/ | ||
public function __construct(array $attributes) | ||
{ | ||
parent::__construct($attributes); | ||
|
||
if(isset($attributes['actions'])) $this->setActions($attributes['actions']); | ||
} | ||
|
||
/** | ||
* Get the actions for the attachment | ||
* | ||
* @return array | ||
*/ | ||
public function getActions() | ||
{ | ||
return $this->actions; | ||
} | ||
|
||
/** | ||
* Set the actions for the attachment | ||
* | ||
* @param array $actions | ||
* @return $this | ||
*/ | ||
public function setActions(array $actions) | ||
{ | ||
$this->clearActions(); | ||
|
||
foreach ($actions as $action) { | ||
$this->addAction($action); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add a action to the attachment | ||
* | ||
* @param mixed $action | ||
* @return $this | ||
*/ | ||
public function addAction($action) | ||
{ | ||
if ($action instanceof AttachmentAction) { | ||
$this->actions[] = $action; | ||
|
||
return $this; | ||
} elseif (is_array($action)) { | ||
$this->actions[] = new AttachmentAction($action); | ||
|
||
return $this; | ||
} | ||
|
||
throw new \InvalidArgumentException('The attachment action must be an instance of '. AttachmentAction::class .' or a keyed array'); | ||
} | ||
|
||
/** | ||
* Clear the actions for the attachment | ||
* | ||
* @return $this | ||
*/ | ||
public function clearActions() { | ||
$this->actions = []; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Convert this attachment to its array representation | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$data = parent::toArray(); | ||
|
||
$data['actions'] = $this->getActionsAsArrays(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Iterates over all actions in this attachment and returns | ||
* them in their array form | ||
* | ||
* @return array | ||
*/ | ||
protected function getActionsAsArrays() | ||
{ | ||
$actions = []; | ||
|
||
foreach ($this->getActions() as $action) $actions[] = $action->toArray(); | ||
|
||
return $actions; | ||
} | ||
} |
Oops, something went wrong.