Package Data | |
---|---|
Maintainer Username: | scottybo |
Maintainer Contact: | scott.bowler@dcsworldwide.net (Scott Bowler) |
Package Create Date: | 2017-09-11 |
Package Last Update: | 2024-08-02 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-09 15:06:35 |
Package Statistics | |
---|---|
Total Downloads: | 7,325 |
Monthly Downloads: | 10 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 3 |
This package allows you to use the TextLocal API in your Laravel 5.5+ app. The core class is a modified version of the demo class provided by TextLocal on: http://api.txtlocal.com/docs/phpclass and uses Guzzle to connect to the API and also provides some additional features not available in the demo class.
Step 1. Install the package in one of two ways:
EITHER via composer:
composer require scottybo/textlocal
OR by adding the following to your composer.json file and running "composer update"
"require": {
...
"scottybo/textlocal": "1.3.*"
}
Step 2. Add the "TextLocal" facade in your config/app.php file
'aliases' => [
...
'TextLocal' => Illuminate\Support\Facades\TextLocal::class,
];
Step 3. You'll now need to publish the configuration file using the command below. A file will be created: config/textlocal.php
php artisan vendor:publish --provider="App\TextLocalApi\TextLocalServiceProvider" --tag="config"
Step 4. Add your TextLocal credentials to your .env file
Important Either specify a Key OR a Hash - don't enter both!
TEXTLOCAL_KEY=
TEXTLOCAL_USERNAME=
TEXTLOCAL_HASH=
Important: View the API docs to see which commands you can use:
In this example we are going to create a command the grab received messages and displays them in the console, using the command php artisan textlocal:get-received-messages
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use TextLocal;
class GetReceivedMessages extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'textlocal:get-received-messages';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Find and store and messages received into Text Local';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Load our inboxes
$inboxes = TextLocal::getInboxes();
$start = 0;
$limit = 1000;
$min_time = strtotime('-1 day');
$max_time = time(); // now
// Loop through the inboxes
foreach($inboxes->inboxes as $inbox) {
// Load the messages for the current inbox (which we will call a folder)
$folder = TextLocal::getMessages($inbox->id, $start, $limit, $min_time,$max_time);
// If there are messages in the folder...
if(sizeof($folder->messages) > 0) {
foreach($folder->messages as $message) {
dump($message->message);
}
}
}
}
}
Want to contribute? Great - push away!