PHPackages                             brandon14/fossabot-commander - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. brandon14/fossabot-commander

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

brandon14/fossabot-commander
============================

Library to easily create Fossabot commands invokable via the Fossabot customapi implementation.

v1.0.4(1y ago)14.9k[3 issues](https://github.com/brandon14/fossabot-commander/issues)[2 PRs](https://github.com/brandon14/fossabot-commander/pulls)1MITPHPPHP ^7.4 || ^8.0

Since Jul 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/brandon14/fossabot-commander)[ Packagist](https://packagist.org/packages/brandon14/fossabot-commander)[ Docs](https://github.com/brandon14/fossabot-commander)[ RSS](/packages/brandon14-fossabot-commander/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (18)Versions (10)Used By (1)

 [![Packagist PHP Version](https://camo.githubusercontent.com/fb6707aa683426f1ff7afafdb50c7f41c8efca7c3d68aef4dca2316ec45720e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465722f7068703f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030)](https://packagist.org/packages/brandon14/fossabot-commander)

 [![GitHub Actions Workflow Status](https://camo.githubusercontent.com/d2400f7c3cc7bddb1d9cd5845f2c8c0d4828709f422edbe794f0511342c99cd0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465722f72756e2d74657374732e796d6c3f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/actions/workflows/run-tests.yml) [![Code Climate maintainability](https://camo.githubusercontent.com/c715108c3bb97f0aa78d9e225126303adc6000fc2335cb6dcc3958e31100eb5e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792d70657263656e746167652f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://codeclimate.com/github/brandon14/fossabot-commander/maintainability) [![Codecov](https://camo.githubusercontent.com/4fbe518464c479943aa974185bfdab4beb0a4458ae30f47c9f7ccc221c746164/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://codecov.io/gh/brandon14/fossabot-commander) [![GitHub](https://camo.githubusercontent.com/733d2d56d1fd079178145c0e9074974dd84d300bdd76a88448fcfd1b0c163612/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/blob/main/LICENSE)

 [![GitHub issues](https://camo.githubusercontent.com/fbf961d228ce219632f895f6bc1fe28d6c816ebb5067f684a4d3ca62c202b180/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/issues) [![GitHub closed issues](https://camo.githubusercontent.com/fe5ec37f32ffb99316ea35845ab70e2d6caf751aa1f1c86f8df2f173d71c261f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d636c6f7365642f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/issues?q=is%3Aissue+is%3Aclosed) [![GitHub pull requests](https://camo.githubusercontent.com/c419331d9106728ba30456cdb31b81168678c15bc164d505d520638e6eb7f7a4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/pulls) [![GitHub closed pull requests](https://camo.githubusercontent.com/d16a4e4b2fa9c4579d974f0d5c12ae6f997a5114fd0a38b641b7fcd3f1d8a058/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722d636c6f7365642f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/pulls?q=is%3Apr+is%3Aclosed)

 [![GitHub release (with filter)](https://camo.githubusercontent.com/bb82cbe98cdc75a87faa0c812067e360cdd82efe7c2743950a7647d47948f39d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/releases) [![GitHub commit activity (branch)](https://camo.githubusercontent.com/57197f2cd2d199f3ccf8457a99c24165fb9c5896c229bb07dfb86443a1c87caa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d69742d61637469766974792f6d2f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/commits/main) [![GitHub last commit (by committer)](https://camo.githubusercontent.com/7cfd000e1aaf7f644cc46888fa474dfb5a54ff3be149cc1ae2ced4f70ef7ddc3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6272616e646f6e31342f666f737361626f742d636f6d6d616e6465723f7374796c653d666f722d7468652d62616467652663616368655365636f6e64733d33363030) ](https://github.com/brandon14/fossabot-commander/commits/main)

brandon14/fossabot-commander
============================

[](#brandon14fossabot-commander)

Source code for [brandon14/fossabot-commander](https://github.com/brandon14/fossabot-commander)
-----------------------------------------------------------------------------------------------

[](#source-code-for-brandon14fossabot-commander)

Table of Contents
-----------------

[](#table-of-contents)

1. [Requirements](https://github.com/brandon14/fossabot-commander#requirements)
2. [Purpose](https://github.com/brandon14/fossabot-commander#purpose)
3. [Installation](https://github.com/brandon14/fossabot-commander#installation)
4. [Usage](https://github.com/brandon14/fossabot-commander#usage)
5. [Standards](https://github.com/brandon14/fossabot-commander#standards)
6. [Coverage](https://github.com/brandon14/fossabot-commander#coverage)
7. [Documentation](https://github.com/brandon14/fossabot-commander#documentation)
8. [Contributing](https://github.com/brandon14/fossabot-commander#contributing)
9. [Versioning](https://github.com/brandon14/fossabot-commander#versioning)
10. [Security Vulnerabilities](https://github.com/brandon14/fossabot-commander#security-vulnerabilities)

Requirements
------------

[](#requirements)

DependencyVersionphp^7.4 || ^8.0ext-json\*psr/http-factory^1.0psr/http-client^1.0psr/log^1.0Purpose
-------

[](#purpose)

I built this library to aid in responding to [Fossabot's](https://docs.fossabot.com/variables/customapi)`customapi` requests when using PHP. If you are running a webserver and want to send Fossabot `customapi`requests to that server, this package allows you to easily write commands and run them to return the text that would display in the chat message. The reason the commands return strings is because Fossabot Fossabot discards any status codes and other HTTP response content, and only uses the raw response body which is a string. This string can be JSON, text, etc.

The normal usage for Fossabot's `customapi` might be something like:

Set command `!foo` to `$(customapi https://foo.bar/foo)`.

When someone types `!foo` in your chat, Fossabot will make a request to `https://foo.bar/foo` and whatever that URl returns will be used as the chat message. With this package, you can easily create commands, and invoke them via the `FossabotCommander::runCommand()` method, and use these utilties in you web framework of choice.

This library validates the Fossabot request using the [request validation](https://docs.fossabot.com/variables/customapi/#validating-requests)endpoint so you can be sure that the request came from Fossabot. You can also optionally (on by default) choose to get additional context about the request as outlined [here](https://docs.fossabot.com/variables/customapi/#validating-requests)to provide more rich integrations with Fossabot. The `FossabotContext` data will be passed into the command's `getResponse` method.

Installation
------------

[](#installation)

```
composer require brandon14/fossabot-commander
```

Usage
-----

[](#usage)

You will first need to get the custom API token from the request header. It will be in the `x-fossabot-customapitoken` header.

For a simple command (using Laravel as an example web framework):

```
// FooCommand.php
