{"id":20696015,"url":"https://github.com/laravel-notification-channels/twitter","last_synced_at":"2025-05-15T07:03:50.285Z","repository":{"id":10468006,"uuid":"65847386","full_name":"laravel-notification-channels/twitter","owner":"laravel-notification-channels","description":"Twitter Notifications Channel for Laravel","archived":false,"fork":false,"pushed_at":"2025-04-07T22:42:50.000Z","size":181,"stargazers_count":173,"open_issues_count":6,"forks_count":45,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-15T07:03:30.101Z","etag":null,"topics":["laravel","laravel-notification-channels","laravel-package"],"latest_commit_sha":null,"homepage":"http://laravel-notification-channels.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laravel-notification-channels.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-08-16T19:23:25.000Z","updated_at":"2025-04-15T09:36:32.000Z","dependencies_parsed_at":"2024-04-03T13:48:12.109Z","dependency_job_id":"3fdbd15e-20aa-4515-b663-f3fee208583d","html_url":"https://github.com/laravel-notification-channels/twitter","commit_stats":{"total_commits":145,"total_committers":26,"mean_commits":5.576923076923077,"dds":0.5517241379310345,"last_synced_commit":"bd321f16b0baa66aa0c982364b860bc89bf03590"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ftwitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ftwitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ftwitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laravel-notification-channels%2Ftwitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laravel-notification-channels","download_url":"https://codeload.github.com/laravel-notification-channels/twitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254291961,"owners_count":22046424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-notification-channels","laravel-package"],"created_at":"2024-11-17T00:12:14.938Z","updated_at":"2025-05-15T07:03:50.266Z","avatar_url":"https://github.com/laravel-notification-channels.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg width=\"1473\" alt=\"image\" src=\"https://user-images.githubusercontent.com/1394539/224646721-20af92f0-2a46-45c0-9700-cfdbe9edf76c.png\"\u003e\n\n\n# Twitter notification channel for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twitter.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twitter)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![StyleCI](https://styleci.io/repos/65847386/shield)](https://styleci.io/repos/65847386)\n[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/twitter.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twitter)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/twitter/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twitter/?branch=master)\n[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twitter.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twitter)\n\nThis package makes it easy to send Laravel notifications using [Twitter](https://dev.twitter.com/rest/public). (Laravel 8+)\n\nPS: v8 now uses the new Twitter API V2. Please read the upgrade guide for your app [here](https://developer.twitter.com/en/docs/twitter-api/migrate/overview).\n\n## Contents\n\n- [About](#about)\n- [Installation](#installation)\n- [Setting up the Twitter service](#setting-up-the-twitter-service)\n- [Usage](#usage)\n    - [Publish a Twitter status update](#publish-a-twitter-status-update)\n    - [Publish Twitter status update with images](#publish-twitter-status-update-with-images)\n    - [Publish Twitter status update with videos](#publish-twitter-status-update-with-videos)\n    - [Publish Twitter status update with both images and videos](#publish-twitter-status-update-with-both-images-and-videos)\n   - [Send a direct message](#send-a-direct-message)\n- [Handle multiple Twitter Accounts](#handle-multiple-twitter-accounts)\n- [Changelog](#changelog)\n- [Testing](#testing)\n- [Security](#security)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## About\n\nThis package is part of the [Laravel Notification Channels](http://laravel-notification-channels.com/) project. It provides additional Laravel Notification channels to the ones given by [Laravel](https://laravel.com/docs/master/notifications) itself.\n\nThe Twitter channel makes it possible to send out Laravel notifications as a `Twitter tweet` (post on the timeline) or as a `direct message`.\n\n## Installation\n\nIf you prefer a video, there is also [an introduction video](https://christoph-rumpel.com/2018/11/sending-laravel-notifications-via-twitter) available for you. If not, just read on.\n\nYou can install this package via composer:\n\n``` bash\ncomposer require laravel-notification-channels/twitter\n```\n\nThe service provider gets loaded automatically.\n\n### Twitter App \u0026 Credentials\n\nYou will need to [create](https://developer.twitter.com/apps/) a Twitter app to use this channel. Within this app, you will find the `keys and access tokens`.\n\nYour Twitter app `must be within a project`. Also, make sure to activate the `user authentication settings`:\n\n\u003cimg width=\"1289\" alt=\"image\" src=\"https://github.com/laravel-notification-channels/twitter/assets/1394539/9be260ba-d8db-4af1-be58-9e4ce3b0176d\"\u003e\n\nAfter that, you have to regenerate your access token and secret. If done correctly, you should see the right permissions for your access tokens:\n\n\u003cimg width=\"796\" alt=\"image\" src=\"https://github.com/laravel-notification-channels/twitter/assets/1394539/6ee5fc99-0373-4ebb-b8c5-4c84a82632df\"\u003e\n\n\nMake sure to copy the right credentials and place them inside your `.env` file.\n\n```env\nTWITTER_CONSUMER_KEY=your-consumer-key\nTWITTER_CONSUMER_SECRET=your-consumer-secret\nTWITTER_ACCESS_TOKEN=your-accesss_token\nTWITTER_ACCESS_SECRET=your-access-token-secret\n```\n\n\u003cimg width=\"1168\" alt=\"image\" src=\"https://github.com/laravel-notification-channels/twitter/assets/1394539/7e68325d-0255-4f66-a310-86f3277f52a7\"\u003e\n\n\nTo load them, add this to your `config/services.php` file:\n\n```php\n...\n'twitter' =\u003e [\n    'consumer_key'    =\u003e env('TWITTER_CONSUMER_KEY'),\n    'consumer_secret' =\u003e env('TWITTER_CONSUMER_SECRET'),\n    'access_token'    =\u003e env('TWITTER_ACCESS_TOKEN'),\n    'access_secret'   =\u003e env('TWITTER_ACCESS_SECRET')\n]\n...\n```\n\n## Usage\n\nTo use this package, you need to create a notification class, like `NewsWasPublished` from the example below, in your Laravel application. Make sure to check out [Laravel's documentation](https://laravel.com/docs/master/notifications) for this process.\n\n### Publish a Twitter status update\n\n```php\n\u003c?php\n\nuse Illuminate\\Notifications\\Notification;\nuse NotificationChannels\\Twitter\\TwitterChannel;\nuse NotificationChannels\\Twitter\\TwitterMessage;\nuse NotificationChannels\\Twitter\\TwitterStatusUpdate;\n\nclass NewsWasPublished extends Notification\n{\n    /**\n     * Get the notification's delivery channels.\n     *\n     * @param  mixed  $notifiable\n     * @return array\n     */\n    public function via($notifiable)\n    {\n        return [TwitterChannel::class];\n    }\n\n    public function toTwitter(mixed $notifiable): TwitterMessage\n    {\n        return new TwitterStatusUpdate('Laravel notifications are awesome!');\n    }\n}\n```\n\nTake a closer look at the `toTwitter` method. Here, we define what kind of Twitter message we want to trigger. In this case, it is a status update message, which is just a new message in your timeline.\n\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n    return new TwitterStatusUpdate('Laravel notifications are awesome!');\n}\n````\n### Publish Twitter status update with images\nIt is possible to publish images with your status update too. You have to pass the image path to the `withImage` method.\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n    return (new TwitterStatusUpdate('Laravel notifications are awesome!'))-\u003ewithImage('marcel.png');\n}\n````\nIf you want to use multiple images, just pass an array of paths.\n````php\nreturn (new TwitterStatusUpdate('Laravel notifications are awesome!'))-\u003ewithImage([\n    public_path('marcel.png'),\n    public_path('mohamed.png')\n]);\n````\n### Publish Twitter status update with videos\nIt is possible to publish videos with your status update too. You have to pass the video path to the `withVideo` method.\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n    return (new TwitterStatusUpdate('Laravel notifications are awesome!'))-\u003ewithVideo('video.mp4');\n}\n````\nIf you want to use multiple videos, just pass an array of paths.\n````php\nreturn (new TwitterStatusUpdate('Laravel notifications are awesome!'))-\u003ewithVideo([\n    public_path('video1.mp4'),\n    public_path('video.gif')\n]);\n````\n### Publish Twitter status update with both images and videos\nIt is also possible to publish both images and videos with your status by using a mixture of the two methods.\n````php\nreturn (new TwitterStatusUpdate('Laravel notifications are awesome!'))-\u003ewithVideo([\n    public_path('video1.mp4'),\n    public_path('video.gif')\n])-\u003ewithImage([\n    public_path('marcel.png'),\n    public_path('mohamed.png')\n]);\n````\n### Publish a Twitter status update in reply to another tweet\nAdditionally, you can publish a status update in reply to another tweet. This is possible by using the `inReplyTo` method.\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n    return (new TwitterStatusUpdate('@christophrumpel Laravel notifications are awesome!'))-\u003einReplyTo(123);\n}\n````\n\u003e Note that the reply status ID will be ignored if you omit the author of the original tweet, according to Twitter docs.\n### Send a direct message (NOT working with the FREE Twitter API plan!)\nTo send a Twitter direct message to a specific user, you will need the `TwitterDirectMessage` class. Provide the Twitter user handler as the first parameter and the message as the second one.\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n     return new TwitterDirectMessage('marcelpociot', 'Hey Marcel, it was nice meeting you at the Laracon.');\n}\n````\n\nYou can also provide the `user ID` instead of the `screen name`. This would prevent an extra Twitter API call. Make sure to pass it as an integer when you do.\n\n````php\npublic function toTwitter(mixed $notifiable): TwitterMessage\n{\n     return new TwitterDirectMessage(12345, 'Hey Marcel, it was nice meeting you at the Laracon.');\n}\n````\n\n## Handle multiple Twitter Accounts\n\nThere might be cases where you need to handle multiple Twitter accounts. This means you need to be able to change the provided keys and tokens of your Twitter app. Luckily, [Laravel](https://laravel.com/docs/master/notifications#customizing-the-recipient) can help you here. In your notifiable model, you can define the `routeNotifiactionForTwitter` method. Here you can override the provided settings.\n\n````php\npublic function routeNotificationForTwitter($notification)\n{\n   return [\n      'TWITTER_CONSUMER_KEY',\n      'TWITTER_CONSUMER_SECRET',\n      'TWITTER_ACCESS_TOKEN',\n      'TWITTER_ACCESS_SECRET',\n   ];\n}\n````\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Security\n\nIf you discover any security-related issues, please email c.rumpel@kabsi.at instead of using the issue tracker.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Christoph Rumpel](https://github.com/christophrumpel)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Ftwitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaravel-notification-channels%2Ftwitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaravel-notification-channels%2Ftwitter/lists"}