Provides simple interfaces to implement a webhook-based tweeting system

Overview

webhook-tweeter

This package aims to provide simple interfaces to implement a webhook-based tweeting system.

This can, for example, be used to tweet a release notification when a new release is published to a GitHub repository.

Installation

composer require ricardoboss/webhook-tweeter

Usage



use ricardoboss\WebhookTweeter\WebhookTweeterConfig;
use ricardoboss\WebhookTweeter\Simple\SimpleWebhookTweeterRenderer;
use ricardoboss\WebhookTweeter\Simple\SimpleWebhookTweeterTemplateLocator;
use ricardoboss\WebhookTweeter\WebhookTweeterHandler;
use ricardoboss\WebhookTweeter\API\BirdElephantTwitterAPI;

// 1. Create a config object
// you can also pass \Stringable objects instead of strings
$config = new WebhookTweeterConfig(
    'webhook_url',
    'webhook_secret' // nullable
);

// 2. Create an instance of WebhookTweeterRenderer
// either use your own renderer or use the simple renderer
$renderer = new SimpleWebhookTweeterRenderer();

// 3. Create a template locator instance
// the simple locator looks for files in the given directory and the given extension (name is passed to the getMatchingTemplate method)
$locator = new SimpleWebhookTweeterTemplateLocator(__DIR__ . '/templates', '.md');

// 4. Create a Twitter API client implementing WebhookTweeterTwitterAPI
$twitter = new BirdElephantTwitterAPI();
$twitter->setCredentials([
    'bearer_token' => xxxxxx, // OAuth 2.0 Bearer Token requests
    'consumer_key' => xxxxxx, // identifies your app, always needed
    'consumer_secret' => xxxxxx, // app secret, always needed
    'token_identifier' => xxxxxx, // OAuth 1.0a User Context requests
    'token_secret' => xxxxxx, // OAuth 1.0a User Context requests
]);

// 5. Create a WebhookTweeterHandler instance
$handler = new WebhookTweeterHandler($config, $renderer, $locator, $twitter);

// 6. Get a PSR-7 request object
$request = /* get your request implementation */;

// 7. Handle the request (sends a rendered tweet)
$result = $handler->handle($request);

The $result variable holds a WebhookTweeterResult instance. The result has the following properties:

  • $result->success: true if the tweet was sent successfully, false otherwise
  • $result->message: an error message if the tweet was not sent successfully
  • $result->url: a URL to the tweet
  • $result->tweet: the tweet object returned from the Twitter API

Credits

Thanks to danieldevine for creating BirdElephant and providing a neat PHP interface for the Twitter V2 API!

License

This project is licensed under the MIT license. Read more about it here.

You might also like...
Implement a
Implement a "Where's Wally" (or Waldo/Charlie) Captcha in a simple Symfony Project

Where's Wally ? Nowadays, we are often confronted with "Captcha". These tests to know if we are robots or not. They are all very boring and not very f

Demonstration of OOP concepts and usage of Abstract class & Interfaces

Learn OOP Demonstration of OOP concepts and usage of Abstract class & Interfaces Usage clone this repo run composer install run php index.php Code str

Bind your interfaces to implementations automatically.
Bind your interfaces to implementations automatically.

Laravel Auto Binder This package automatically binds interfaces to implementations in the Service Container, scanning the specified project folders. T

bin/magento command to display configured preferences for classes or interfaces

bin/magento command to display configured preferences for classes or interfaces A bin/magento command that will show you the configured preferences fo

This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file

marijnvanwezel/reflection-file Library that allows reflection of files. This library can be used, among other things, to retrieve the classes, interfa

The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

PHPStan extension for sealed classes and interfaces.

Sealed classes with PHPStan This extension adds support for sealed classes and interfaces to PHPStan. Installation To use this extension, require it v

Um repositório com classes, interfaces para padronizar os projetos de PHP da empresa

php-utils PHP Utilities for Laravel/Lumen Installation cd /path/to/your/project composer require logcomex/php-utils Utilities Packages Contracts Excep

The only way to implement the pipe operator in PHP.

Pipe Operator in PHP Introduction This package is based on the pipe operator RFC by Sara Golemon and Marcelo Camargo (2016), who explains the problem

Releases(v0.4)
Laradeploy offers you to automate deployment using a GitHub webhook.

Introduction Laradeploy offers you to automate deployment using a GitHub webhook. Simple and fast just make a git push to GitHub deploy the new modifi

Gentrit Abazi 10 Feb 21, 2022
A Discord Webhook Application with the Coinbase API

Ein PHP-Skript um einen Kryptowährungspreis in Discord darzustellen. Installation Windows Voraussetzungen Docker vollständig installiert Discord und e

Nevah 3 Oct 15, 2022
An easy code to send messages on a discord text channel with webhook.

Status Webhook-Discord An easy code to send messages on a discord text channel with webhook. Don't forget to check the latest version of Webhook-Disco

Victor 1 Dec 3, 2021
[Virion] A library that helps you use Discord Webhook

DiscordHelper How to register Web Hook URL How to register Web Hook URL use NewThing\DiscordHelper\DiscordHelper; DiscordHelper::setURL($YourWebHookU

null 1 Dec 25, 2021
Contact Form7 - KeepinCRM connector via Webhook

Contact Form7 - KeepinCRM connector Плагін для відправки даних з форм на Contact Form7 до KeepinCRM через Webhook. Встановлення Вивантажити плагін арх

null 1 Aug 11, 2022
Receiver is a drop-in webhook handling library for Laravel.

Receiver Receiver is a drop-in webhook handling library for Laravel. Webhooks are a powerful part of any API lifecycle. Receiver aims to make handling

Adam Campbell 270 Jan 6, 2023
An easy-to-use API for Discord webhook

WebhookAPI An easy-to-use API for Discord webhook İmage: Example Add use use ayd1ndemirci\WebhookAPI; Usage: $webhook = "your_discord_webhook_url";

Aydın Demirci 5 Jun 7, 2023
This Pocketmine-MP plugin lets you implement the ultimate birthday wishing system on your server.

BirthdaysPE This Pocketmine-MP plugin will let you wish player(s) a happy birthday and notify others to wish them too. Commands /birthday <set/reset>

MCA7 3 Jul 25, 2022
a simple pastebin implement in php

alcohol/pastebin-php I mostly use this demo application to keep myself up to date with the various changes introduced by new (major) Symfony releases.

Rob 26 Nov 5, 2022
Simple class that implement a CAPTCHA for your PHP App.

simple-captcha Simple class that implement a CAPTCHA for your PHP App. Installation Use the package manager composer to install. composer require will

WILLIAM B. SAMPAIO 3 Nov 9, 2022