slack/src/Options/Base.php
2022-09-05 11:43:38 +10:00

67 lines
1.7 KiB
PHP

<?php
namespace Slack\Options;
use Illuminate\Support\Facades\Log;
use Slack\Base as SlackBase;
use Slack\Message;
abstract class Base extends SlackBase
{
private const LOGKEY = 'SOb';
// Does the event respond with a reply to the HTTP request, or via a post with a trigger
// Child class should have a respond() function.
// (There should be a local implementation of the child class should respondNow = TRUE)
public $respondNow = FALSE;
public function __construct(array $request)
{
Log::info(sprintf('%s:Slack INTERACTIVE MESSAGE Initialised [%s]',self::LOGKEY,get_class($this)),['m'=>__METHOD__]);
// Our data is in a payload value
parent::__construct($request);
}
/**
* Enable getting values for keys in the response
*
* @note: This method is limited to certain values to ensure integrity reasons
* @note: Classes should return:
* + channel_id,
* + team_id,
* + ts,
* + user_id
* @param string $key
* @return mixed|object
*/
public function __get(string $key)
{
switch ($key) {
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');
case 'callback_id':
//case 'action_ts':
//case 'message_ts':
case 'type':
return object_get($this->_data,$key);
}
}
/**
* 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
*/
abstract public function respond(): Message;
}