Listener code tidyup - consistent use of slack queue "slack"

This commit is contained in:
Deon George 2022-09-04 10:21:52 +10:00
parent 89c13bcb73
commit b6dc14971f
13 changed files with 27 additions and 26 deletions

View File

@ -20,11 +20,11 @@ class AppHomeOpenedListener implements ShouldQueue
* @param AppHomeOpened $event
* @return void
*/
public function handle(AppHomeOpened $event)
public function handle(AppHomeOpened $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:App Home Page open for [%s] in team [%s]',self::LOGKEY,$event->user_id,$event->team_id),['m'=>__METHOD__]);
dispatch((new SlackHomeTabUpdate($event->user(),$event->team(TRUE),$event->tab,$event->view))->onQueue('high'));
dispatch((new SlackHomeTabUpdate($event->user(),$event->team(TRUE),$event->tab,$event->view))->onQueue('slack'));
}
}

View File

@ -2,6 +2,7 @@
namespace Slack\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Slack\Jobs\DeleteChat;
@ -10,9 +11,12 @@ use Slack\Interactive\BlockActions;
/**
* This class handles BlockActions events.
* It's expected that the local application would implement this class completely, rather than using this
* modules implementation.
* module's implementation.
*
* @note Since block actions contain a trigger_id, we shouldnt queue this as the trigger_id may have expired by the time
* the queue runs the job. (trigger_id's only last 3 seconds)
*/
class BlockActionListener
class BlockActionListener //implements ShouldQueue
{
protected const LOGKEY = 'LBA';
@ -60,7 +64,7 @@ class BlockActionListener
switch ($event->action_id) {
case 'self_destruct':
// Queue the delete of the message
dispatch((new DeleteChat($event->user(),$event->message_ts))->onQueue('low'));
dispatch((new DeleteChat($event->user(),$event->message_ts))->onQueue('slack'));
// @todo If this message is on integrations messages channel, which is not the user_id() - need to use the user's integration direct channel ID
break;

View File

@ -2,10 +2,12 @@
namespace Slack\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Slack\Options\BlockSuggestion;
class BlockSuggestionListener
class BlockSuggestionListener implements ShouldQueue
{
private const LOGKEY = 'LBS';

View File

@ -19,7 +19,7 @@ class ChannelJoinListener implements ShouldQueue
* @param MemberJoinedChannel $event
* @return void
*/
public function handle(MemberJoinedChannel $event)
public function handle(MemberJoinedChannel $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:User [%s] joined Channel [%s]',self::LOGKEY,$event->invited,$event->channel_id),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class ChannelLeftListener implements ShouldQueue
* @param Base $event
* @return void
*/
public function handle(Base $event)
public function handle(Base $event): void
{
if (! $event instanceof ChannelLeft AND ! $event instanceof GroupLeft)
abort(500,'Wrong class calling this listener? '.get_class($event));

View File

@ -19,7 +19,7 @@ class InteractiveMessageListener implements ShouldQueue
* @param InteractiveMessage $event
* @return void
*/
public function handle(InteractiveMessage $event)
public function handle(InteractiveMessage $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Interactive Message for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class MessageListener implements ShouldQueue
* @param Message $event
* @return void
*/
public function handle(Message $event)
public function handle(Message $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Message event [%s] - subtype [%s]',self::LOGKEY,$event->ts,$event->type),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class PinAddedListener implements ShouldQueue
* @param PinAdded $event
* @return void
*/
public function handle(PinAdded $event)
public function handle(PinAdded $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Pin Added to message [%s] in [%s]',self::LOGKEY,$event->ts,$event->channel_id),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class PinRemovedListener implements ShouldQueue
* @param PinRemoved $event
* @return void
*/
public function handle(PinRemoved $event)
public function handle(PinRemoved $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Pin Removed from message [%s] in [%s]',self::LOGKEY,$event->ts,$event->channel_id),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class ReactionAddedListener implements ShouldQueue
* @param ReactionAdded $event
* @return void
*/
public function handle(ReactionAdded $event)
public function handle(ReactionAdded $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Reaction [%s] added to message in [%s]',self::LOGKEY,$event->reaction,$event->team_id),['m'=>__METHOD__]);

View File

@ -2,6 +2,7 @@
namespace Slack\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Slack\Blockkit\Blocks\Elements\Text;
@ -20,30 +21,24 @@ class ShortcutListener //implements ShouldQueue
* Handle the event.
*
* @param Shortcut $event
* @return Message|null
* @return void
* @throws \Exception
* @todo To Test
*/
public function handle(Shortcut $event): ?Message
public function handle(Shortcut $event): void
{
if (! $event->channel() || ! $event->channel()->active) {
$modal = new Modal(Text::item(config('app.name'),'plain_text'));
$modal->addBlock(
Header::item(Text::item(':robot_face: Bot not in this channel','plain_text'))
)
->addBlock(
Section::item(Text::item('Please add the BOT to this channel and try this again.'))
);
$modal->addBlock(Header::item(Text::item(':robot_face: Bot not in this channel','plain_text')))
->addBlock(Section::item(Text::item('Please add the BOT to this channel and try this again.')));
try {
$event->team()->slackAPI()->viewOpen($event->trigger_id,json_encode($modal));
$event->team()->slackAPI()->viewOpen($event->trigger_id,$modal);
} catch (\Exception $e) {
Log::error(sprintf('%s:Got an error posting view to slack: %s',static::LOGKEY,$e->getMessage()),['m'=>__METHOD__]);
}
return (new Message)->blank();
}
// Do some magic with event data

View File

@ -19,7 +19,7 @@ class ViewClosedListener implements ShouldQueue
* @param ViewClosed $event
* @return void
*/
public function handle(ViewClosed $event)
public function handle(ViewClosed $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:Block Action for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);

View File

@ -19,7 +19,7 @@ class ViewSubmissionListener implements ShouldQueue
* @param ViewSubmission $event
* @return void
*/
public function handle(ViewSubmission $event)
public function handle(ViewSubmission $event): void
{
// Do some magic with event data
Log::info(sprintf('%s:View Submission for Callback [%s] User [%s] in [%s]',self::LOGKEY,$event->callback_id,$event->user_id,$event->team_id),['m'=>__METHOD__]);