say('example', '#botman-tests', SlackDriver::class, [ 'attachments' => json_encode([ [ 'fallback' => 'Upgrade your Slack client to use messages like these.', 'color' => '#CC0000', 'actions' => [ [ 'type' => 'button', 'text' => ':red_circle: Complete Task: '.$task_id, 'url' => url('/workflow/'.$task_id), ] ] ] ]) ]); // Retrieve API result $result = json_decode($result->getContent(), true); // Store the task in the cache $storedTasks = \Cache::get('tasks', []); $storedTasks[$task_id] = [ 'channel' => $result['channel'], 'ts' => $result['message']['ts'], ]; \Cache::put('tasks', $storedTasks, 60); }); Route::get('/workflow/{task_id}', function($task_id) { return response('
'); }); Route::post('/complete/{task_id}', function($task_id) { $tasks = \Cache::get('tasks'); $task = $tasks[$task_id]; /** * This is where your app's business logic would live. * Once the task has been complete, the user will be directed to this `/complete` * page, which shows a link back to their Slack conversation */ /** * When this page loads, we update the original Slack message to show that * the pending task has been completed */ $botman = app('botman'); $botman->loadDriver(SlackDriver::class); $botman->sendRequest('chat.update', [ 'channel' => $task['channel'], 'ts' => $task['ts'], 'text' => 'Task Complete!', 'attachments' => json_encode([ [ 'fallback' => 'Upgrade your Slack client to use messages like these.', 'color' => '#36a64f', 'text' => ':white_check_mark: *Completed Task: '.$task_id.'*', 'mrkdwn_in' => ['text'] ] ]) ]); // Get the message permalink to redirect the user back to Slack $result = $botman->sendRequest('chat.getPermalink', [ 'channel' => $task['channel'], 'message_ts' => $task['ts'], ]); $result = json_decode($result->getContent(), true); return response('Return to Slack'); });