Options code tidyup
This commit is contained in:
parent
b6dc14971f
commit
ff00e88417
@ -39,14 +39,12 @@ abstract class Base extends SlackBase
|
||||
public function __get(string $key)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'team_id':
|
||||
return object_get($this->_data,'team.id');
|
||||
case 'channel_id':
|
||||
return object_get($this->_data,'channel.id');
|
||||
|
||||
case 'enterprise_id':
|
||||
return object_get($this->_data,'team.'.$key);
|
||||
|
||||
case 'team_id':
|
||||
return object_get($this->_data,'team.id');
|
||||
case 'user_id':
|
||||
return object_get($this->_data,'user.id');
|
||||
|
||||
@ -59,23 +57,11 @@ abstract class Base extends SlackBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive messages can return their output in the incoming HTTP post
|
||||
* Interactive messages can return their output in the incoming HTTP post.
|
||||
* This function should be overwritten in the parent class, and finish by calling return Message::blank();
|
||||
*
|
||||
* @return Message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function respond(): Message
|
||||
{
|
||||
Log::info(sprintf('%s:Interactive Option - Callback [%s] Name [%s] Value [%s]',self::LOGKEY,$this->callback_id,$this->name,$this->value),['m'=>__METHOD__]);
|
||||
|
||||
if (preg_match('/^(.*)\|([0-9]+)/',$this->callback_id)) {
|
||||
[$action,$id] = explode('|',$this->callback_id,2);
|
||||
|
||||
} else {
|
||||
// If we get here, its an action that we dont know about.
|
||||
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',self::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
|
||||
}
|
||||
|
||||
return Message::blank();
|
||||
}
|
||||
abstract public function respond(): Message;
|
||||
}
|
@ -126,7 +126,7 @@ use Slack\Message;
|
||||
)
|
||||
)
|
||||
*/
|
||||
class BlockSuggestion extends Base
|
||||
abstract class BlockSuggestion extends Base
|
||||
{
|
||||
protected const LOGKEY = 'OIM';
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Slack\Options;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -26,13 +25,15 @@ class Factory {
|
||||
* @param string $type
|
||||
* @param array $request
|
||||
* @return Base
|
||||
* @note Options classes must be defined in the calling application and extend these self::map abstract classes
|
||||
* otherwise errors will be thrown
|
||||
*/
|
||||
public static function create(string $type,array $request)
|
||||
{
|
||||
$class = Arr::get(config('slack.options',self::map),$type,Unknown::class);
|
||||
Log::debug(sprintf('%s:Working out Interactive Options Event Class for [%s] as [%s]',static::LOGKEY,$type,$class),['m'=>__METHOD__]);
|
||||
|
||||
if (App::environment() == 'dev')
|
||||
if (App::environment() == 'local')
|
||||
file_put_contents('/tmp/option.'.$type,print_r(json_decode($request->input('payload')),TRUE));
|
||||
|
||||
return new $class($request);
|
||||
|
@ -33,7 +33,7 @@ use Slack\Message;
|
||||
* [attachment_id] => 3
|
||||
* [token] => Oow8S2EFvrZoS9z8N4nwf9Jo
|
||||
*/
|
||||
class InteractiveMessage extends Base
|
||||
abstract class InteractiveMessage extends Base
|
||||
{
|
||||
protected const LOGKEY = 'OIM';
|
||||
|
||||
@ -49,25 +49,4 @@ class InteractiveMessage extends Base
|
||||
return parent::__get($key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive messages can return their output in the incoming HTTP post
|
||||
*
|
||||
* @return Message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function respond(): Message
|
||||
{
|
||||
Log::info(sprintf('%s:Interactive Option - Callback [%s] Name [%s] Value [%s]',static::LOGKEY,$this->callback_id,$this->name,$this->value),['m'=>__METHOD__]);
|
||||
|
||||
if (preg_match('/^(.*)\|([0-9]+)/',$this->callback_id)) {
|
||||
[$action,$id] = explode('|',$this->callback_id,2);
|
||||
|
||||
} else {
|
||||
// If we get here, its an action that we dont know about.
|
||||
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',static::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
|
||||
}
|
||||
|
||||
return (new Message)->blank();
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ namespace Slack\Options;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use Slack\Message;
|
||||
|
||||
/**
|
||||
* Catch all unknown slack event that we havent specifically programmed for.
|
||||
*
|
||||
@ -11,10 +13,27 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
final class Unknown extends Base
|
||||
{
|
||||
protected const LOGKEY = 'OU-';
|
||||
|
||||
public function __construct(array $request)
|
||||
{
|
||||
Log::notice(sprintf('SOU:UNKNOWN Slack Interaction Option received [%s]',get_class($this)),['m'=>__METHOD__]);
|
||||
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactive messages can return their output in the incoming HTTP post
|
||||
*
|
||||
* @return Message
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function respond(): Message
|
||||
{
|
||||
Log::info(sprintf('%s:Unknown Option - Callback [%s] Name [%s] Value [%s]',static::LOGKEY,$this->callback_id,$this->name,$this->value),['m'=>__METHOD__]);
|
||||
|
||||
Log::notice(sprintf('%s:Unhandled CALLBACK [%s]',static::LOGKEY,$this->callback_id),['m'=>__METHOD__]);
|
||||
|
||||
return Message::blank();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user