Introduction | laravel-slack-slash-command | Spatie

 SPATIE

  Laravel Slack Slash Command
==============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-slack-slash-command](https://spatie.be/docs/laravel-slack-slash-command/v1)  Introduction

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-slack-slash-command/v1)

- [ Introduction ](https://spatie.be/docs/laravel-slack-slash-command/v1/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-slack-slash-command/v1/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-slack-slash-command/v1/requirements)
- [ Installation and Setup ](https://spatie.be/docs/laravel-slack-slash-command/v1/installation-and-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-slack-slash-command/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-slack-slash-command/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-slack-slash-command/v1/about-us)

Usage
-----

- [ General flow ](https://spatie.be/docs/laravel-slack-slash-command/v1/usage/general-flow)
- [ Sending a basic response ](https://spatie.be/docs/laravel-slack-slash-command/v1/usage/sending-a-basic-response)
- [ Making your response look good ](https://spatie.be/docs/laravel-slack-slash-command/v1/usage/making-your-response-look-good)
- [ Making your attachments interactive ](https://spatie.be/docs/laravel-slack-slash-command/v1/usage/making-your-attachments-interactive)

Advanced usage
--------------

- [ Sending delayed responses ](https://spatie.be/docs/laravel-slack-slash-command/v1/advanced-usage/sending-delayed-responses)
- [ Using signature handlers ](https://spatie.be/docs/laravel-slack-slash-command/v1/advanced-usage/using-signature-handlers)
- [ Responding to multiple commands ](https://spatie.be/docs/laravel-slack-slash-command/v1/advanced-usage/responding-to-multiple-commands)

 Laravel Slack Slash Command
=============================

 Make a Laravel app respond to a slash command from Slack

 [    Repository ](https://github.com/spatie/laravel-slack-slash-command)

    609,427

    254

Introduction
------------

###  On this page

1. [ We have badges! ](#content-we-have-badges)

This package makes it easy to make your Laravel app respond to [Slack's Slash commands](https://api.slack.com/slash-commands).

Once you've setup your Slash command over at Slack and installed this package into a Laravel app you can create handlers that can handle a slash command. Here's an example of such a handler that will send a response back to Slack.

```
namespace App\SlashCommandHandlers;

use App\SlashCommand\BaseHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;

class CatchAll extends BaseHandler
{
    /**
     * If this function returns true, the handle method will get called.
     *
     * @param \Spatie\SlashCommand\Request $request
     *
     * @return bool
     */
    public function canHandle(Request $request): bool
    {
        return true;
    }

    /**
     * Handle the given request. Remember that Slack expects a response
     * within three seconds after the slash command was issued. If
     * there is more time needed, dispatch a job.
     *
     * @param \Spatie\SlashCommand\Request $request
     *
     * @return \Spatie\SlashCommand\Response
     */
    public function handle(Request $request): Response
    {
        return $this->respondToSlack("You have typed this text: `{$request->text}`");
    }
}
```

The package also provides many options to format a response. It also can respond to Slack from within a queued job.

We have badges!
---------------------------------------------------------------------------------------------------

 [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-slack-slash-command.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-slack-slash-command) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/spatie/laravel-slack-slash-command/blob/master/LICENSE.md) [![Build Status](https://img.shields.io/travis/spatie/laravel-slack-slash-command/master.svg?style=flat-square)](https://travis-ci.org/spatie/laravel-slack-slash-command) [![SensioLabsInsight](https://img.shields.io/sensiolabs/i/20a38dd4-06a0-401f-bd51-1d3f05fcdff5.svg?style=flat-square)](https://insight.sensiolabs.com/projects/20a38dd4-06a0-401f-bd51-1d3f05fcdff5) [![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-slack-slash-command.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-slack-slash-command) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-slack-slash-command.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-slack-slash-command)
