slack/src/Options/InteractiveMessage.php
2022-08-23 17:48:09 +10:00

73 lines
1.6 KiB
PHP

<?php
namespace Slack\Options;
use Illuminate\Support\Facades\Log;
use Slack\Message;
/**
* Class InteractiveMessage
*
* [name] => source
* [value] =>
* [callback_id] => classify|46
* [type] => interactive_message
* [team] => stdClass Object
* (
* [id] => {SLACKTEAM}
* [domain] => {SLACKDOMAIN}
* )
* [channel] => stdClass Object
* (
* [id] => {SLACKCHANNEL}
* [name] => directmessage
* )
* [user] => stdClass Object
* (
* [id] => {SLACKUSER}
* [name] => {SLACKUSER}
* )
* [action_ts] => 1603780652.484943
* [message_ts] => 1601349865.001500
* [attachment_id] => 3
* [token] => Oow8S2EFvrZoS9z8N4nwf9Jo
*/
class InteractiveMessage extends Base
{
protected const LOGKEY = 'OIM';
public function __get($key)
{
switch ($key) {
case 'name':
case 'value':
case 'message_ts':
return object_get($this->_data,$key);
default:
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();
}
}