Download the PHP package brandon14/fossabot-commander without Composer
On this page you can find all versions of the php package brandon14/fossabot-commander. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brandon14/fossabot-commander
More information about brandon14/fossabot-commander
Files in brandon14/fossabot-commander
Package fossabot-commander
Short Description Library to easily create Fossabot commands invokable via the Fossabot customapi implementation.
License MIT
Homepage https://github.com/brandon14/fossabot-commander
Informations about the package fossabot-commander
brandon14/fossabot-commander
Source code for brandon14/fossabot-commander
Table of Contents
- Requirements
- Purpose
- Installation
- Usage
- Standards
- Coverage
- Documentation
- Contributing
- Versioning
- Security Vulnerabilities
Requirements
Dependency | Version |
---|---|
php | ^7.4 || ^8.0 |
ext-json | * |
psr/http-factory | ^1.0 |
psr/http-client | ^1.0 |
psr/log | ^1.0 |
Purpose
I built this library to aid in responding to Fossabot's
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
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
to provide more rich integrations with Fossabot. The FossabotContext
data will be passed into the
command's getResponse
method.
Installation
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):
You can also provide a callable to the runCommand()
instead of an instance of a
FossabotCommand
provided the callable returns a string and takes an optional
FossabotContext|null
parameter.
This gives you an easier to implement method for quick commands that don't need a lot of external dependencies, or otherwise a more portable method to send Fossabot messages back.
The FossabotCommander
class requires a PSR compliant ClientInterface
and a PSR compliant
RequestFactoryInterface
. These can be provided by libraries like guzzlehttp/guzzle
or other PSR
compliant libraries. In the above example with Laravel we are assuming that the Laravel container
has the FossabotCommander
instance bound to the container.
For more complicated commands, the sky is the limit. Depending on how you want to build and instantiate
your FossabotCommand
instances, you can use the FossabotContext
data to provide rich integration
for your Fossabot chatbot!
Usage with Laravel:
If you are planning on using fossabot-commander
in a Laravel project, check out
the Laravel package fossabot-commander-laravel
that I made for easy integration within the Laravel ecosystem.
Standards
We strive to meet the PSR-12 coding style for PHP projects, and enforce our
coding standard via the php-cs-fixer linting tool. Our ruleset can be
found in the .php-cs-fixer.dist.php
file.
Coverage
The latest code coverage information can be found via Codecov. We strive to maintain 100% coverage across the entire library, so if you are contributing, please make sure to include tests for new code added.
Documentation
Documentation to this project can be found here.
Contributing
Got something you want to add? Found a bug or otherwise bad code? Feel free to submit pull requests to add in new features, fix bugs, or clean things up. Just be sure to follow the Code of Conduct and Contributing Guide, and we encourage creating clean and well described pull requests if possible.
If you notice an issues with the library or want to suggest new features, feel free to create issues appropriately using the issue tracker.
In order to run the tests, it is recommended that you sign up for a Cloudinary account (it's a free service), and use that
account to run the full integration tests. In order to do that, you will need to copy .env.example
to .env
and fill
in the variables using the details in your account. The integration tests will use random prefixed directories and clean
everything up before and after the tests.
Versioning
brandon14/fossabot-commander
uses semantic versioning that looks like MAJOR.MINOR.PATCH
.
Major version changes will include backwards-incompatible changes and may require refactoring of projects using it. Minor version changes will include backwards-compatible new features and changes and will not break existing usages. Patch version changes will include backwards-compatible bug and security fixes, and should be updated as soon as possible.
Security Vulnerabilities
If you discover a vulnerability within this package, please email Brandon Clothier via [email protected]. All security vulnerabilities will be promptly addressed.
This code is released under the MIT license.
Copyright © 2023-2024 Brandon Clothier
All versions of fossabot-commander with dependencies
ext-json Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/log Version ^1.0 || ^2.0 || ^3.0