diff --git a/src/API.php b/src/API.php index a07f722..4e798d0 100644 --- a/src/API.php +++ b/src/API.php @@ -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 * diff --git a/src/Message.php b/src/Message.php index bd1cc87..aff59ec 100644 --- a/src/Message.php +++ b/src/Message.php @@ -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'); diff --git a/src/Response/Base.php b/src/Response/Base.php index c3303f0..219d022 100644 --- a/src/Response/Base.php +++ b/src/Response/Base.php @@ -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':