| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\Integrations\Slack; |
| 4 |
|
| 5 |
use FluentForm\App\Helpers\Helper; |
| 6 |
use FluentForm\Framework\Foundation\Application; |
| 7 |
|
| 8 |
class SlackNotificationActions |
| 9 |
{ |
| 10 |
protected $app = null; |
| 11 |
|
| 12 |
public function __construct(Application $app) |
| 13 |
{ |
| 14 |
$this->app = $app; |
| 15 |
// add_filter('fluentform_notifying_async_slack', '__return_false'); |
| 16 |
} |
| 17 |
|
| 18 |
public function register() |
| 19 |
{ |
| 20 |
add_filter('fluentform_global_notification_active_types', function ($types) { |
| 21 |
$isEnabled = Helper::isSlackEnabled(); |
| 22 |
if ($isEnabled) { |
| 23 |
$types['slack'] = 'slack'; |
| 24 |
} |
| 25 |
return $types; |
| 26 |
}); |
| 27 |
add_action('fluentform_integration_notify_slack', array($this, 'notify'), 20, 4); |
| 28 |
} |
| 29 |
|
| 30 |
public function notify($feed, $formData, $entry, $form) |
| 31 |
{ |
| 32 |
$isEnabled = Helper::isSlackEnabled(); |
| 33 |
if (!$isEnabled) { |
| 34 |
return; |
| 35 |
} |
| 36 |
$response = Slack::handle($feed, $formData, $form, $entry); |
| 37 |
if ($response['status'] === 'success') { |
| 38 |
do_action('ff_log_data', [ |
| 39 |
'parent_source_id' => $form->id, |
| 40 |
'source_type' => 'submission_item', |
| 41 |
'source_id' => $entry->id, |
| 42 |
'component' => 'slack', |
| 43 |
'status' => 'success', |
| 44 |
'title' => $feed['meta_key'], |
| 45 |
'description' => 'Slack feed has been successfully initialed and pushed data' |
| 46 |
]); |
| 47 |
} else { |
| 48 |
do_action('ff_log_data', [ |
| 49 |
'parent_source_id' => $form->id, |
| 50 |
'source_type' => 'submission_item', |
| 51 |
'source_id' => $entry->id, |
| 52 |
'component' => 'slack', |
| 53 |
'status' => 'failed', |
| 54 |
'title' => $feed['meta_key'], |
| 55 |
'description' => $response['message'] |
| 56 |
]); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|