Add scheduled messages

This commit is contained in:
Deon George 2021-12-08 14:21:57 +11:00
parent 1a5371a7b9
commit 66031eff47
3 changed files with 47 additions and 0 deletions

View File

@ -40,6 +40,8 @@ class API
'dialog.open'=>'', // No scope required
'pins.add'=>'pins:write',
'pins.remove'=>'pins:write',
'chat.scheduleMessage'=>'chat:write',
'chat.scheduledMessages.list'=>'',
'team.info'=>'team:read',
'views.open'=>'', // No scope required
'views.publish'=>'', // No scope required
@ -226,6 +228,34 @@ class API
return new Generic($this->execute('chat.postMessage',json_encode($request)));
}
/**
* Schedule a slack message
*
* @param Message $request
* @return Generic
* @throws \Exception
*/
public function scheduleMessage(Message $request): Generic
{
Log::debug(sprintf('%s:Scheduling a Slack Message',static::LOGKEY),['m'=>__METHOD__,'r'=>$request]);
return new Generic($this->execute('chat.scheduleMessage',json_encode($request)));
}
/**
* Get the scheduled messages
*
* @param Message $request
* @return Generic
* @throws \Exception
*/
public function scheduleMessagesList(string $request=NULL): Generic
{
Log::debug(sprintf('%s:Get the Scheduled Messages in Slack',static::LOGKEY),['m'=>__METHOD__,'r'=>$request]);
return new Generic($this->execute('chat.scheduledMessages.list',$request ? ['channel'=>$request] : []));
}
/**
* Remove a Pin from a message
*

View File

@ -150,6 +150,22 @@ class Message implements \JsonSerializable
return $response;
}
/**
* Schedule a message
*
* @param Carbon $time
* @return Generic
*/
public function schedule(Carbon $time): Generic
{
$this->_data->put('post_at',$time->timestamp);
$api = $this->o->team->slackAPI();
$response = $this->_data->has('ts') ? $api->updateMessage($this) : $api->scheduleMessage($this);
return $response;
}
public function setReplace(bool $replace=TRUE): self
{
$this->_data->put('replace_original',$replace ? 'true' : 'false');

View File

@ -51,6 +51,7 @@ class Base extends SlackBase implements \JsonSerializable
return object_get($this->_data,$key) ?: object_get($this->_data,'channel');
case 'messages': // Used by getMessageHistory()
case 'scheduled_messages': // Used by scheduledMessagesList()
return collect(object_get($this->_data,$key));
case 'team_id':