giagara/laravel-asana-webhook

Laravel asana webhook integration

1.0.4 2023-05-01 13:55 UTC

This package is auto-updated.

Last update: 2024-10-20 11:59:19 UTC


README

CI/CD Packagist codecov

This package let you integrate easily with Asana Webhooks.

Installation

Install the package via composer:

composer require giagara/laravel-asana-webhook

Publish config file with

php artisan vendor:publish --tags=asana-webhook

Usage

First of all you need to configure the personal access token to communicate with Asana. You can get it here: https://developers.asana.com/docs/personal-access-token

Add it in your .env file

ASANA_PERSONAL_ACCESS_TOKEN=your_token

Configure the routing by adding items to the route array in config file.

'routes' => [
    'webhook' => AnInvokableClass::class
],

Alternatively the configuration can support name and middlewares

'routes' => [
    'webhook' => [
        'class' => AnInvokableClass::class,
        'name' => 'webhook-1',
        'middleware' => [CustomMiddleware::class],
    ]
]

NOTE: the invokable class must implements AsanaActionInterface. NOTE: the route is forced to use api/ prefix so, in this case, the final path will be api/webhook.

Example:

use Giagara\AsanaWebhook\Contracts\AsanaActionInterface;

class FakeInvokableClass implements AsanaActionInterface
{
    public function __invoke(array $payload) : void
    {

        // do something

    }

}

After this the route api/webhook will be mapped to your invokable class.

Available commands

Webhook list

php artisan asana:list-webhook

NOTE: For this feature create ASANA_WORKSPACE_ID field in .env file.

get workspace id by calling this url

Webhook creation

To create a new webhook in Asana you can use the CreateWebhookCommand by calling:

php artisan asana:create-webhook

It will ask for resource id (see Asana documentation) and target url (that should be already reachable by Asana).

You can pass the parameters in command directly with:

php artisan asana:create-webhook --resource=1234 --target=https://example.com/api/webhook
php artisan asana:create-webhook --resource=1234 --route=route-name

The --route parameter is the route name: see php artisan route:list

Delete Webhook

php artisan asana:delete-webhook {webhook_gid}

TODO

  • Create webhook list command
  • Delete a webhook via command
  • Add middleware to route configs
  • Add name to route config
  • Trigger via route name

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email giagara@yahoo.it instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.