Git Product home page Git Product logo

laravel-txtbox's Introduction

Laravel TxtBox

TxtBox SMS API for Laravel.

Packagist Version Packagist

What is TxtBox

Txtbox lets you send an SMS with a single line of code. No complicated setup, no dealing with telecom protocols and procedures.

For more info, you can visit their website at: https://www.txtbox.com

Requirements

  • PHP: 7.2.x and up or 8.0.x
  • Laravel: 8.x.x (For Laravel 7.x.x, use version 1.x.x)
  • TxtBox API Key

Installation

Install using Composer

For Laravel 8:
$ composer require woenel/laravel-txtbox

For Laravel 7:
$ composer require woenel/laravel-txtbox "^1.3"

Publish the config file named txtbox.php and set the TxtBox API key.

$ php artisan vendor:publish --provider="Woenel\TxtBox\TxtBoxServiceProvider"

Usage

Send a Message

These are the three methods you can use to send a message:

1. Using facade
use Woenel\TxtBox\Facades\TxtBox;

$result = TxtBox::to('09123456789')->message('Hello World!')->send();

if($result->success) {
  echo $result->message;
} else {
  echo $result->message;
}
2. Instantiating class (chaining)
use Woenel\TxtBox\TxtBox;

$txtbox = new TxtBox;

$result = $txtbox->to('09123456789')->message('Hello World!')->send();

if($result->success) {
  echo $result->message;
} else {
  echo $result->message;
}
3. Instantiating class (one-by-one)
use Woenel\TxtBox\TxtBox;

$txtbox = new TxtBox;

$txtbox->to = '09123456789';
$txtbox->message = 'Hello World!';
$result = $txtbox->send();

if($result->success) {
  echo $result->message;
} else {
  echo $result->message;
}

Success and Failure returns

TxtBox Laravel API returns object-type values.

Success

Message successfully sent to 09XXXXXXXXX
This happens when you successfully sent a message.

{
  "success": true,
  "message": 'Message successfully sent to 09XXXXXXXXX'
}

Failures

Invalid Token
This happens when you did not provide a valid API key. API key can be modified in txtbox.php file under config folder.

{
  "success": false,
  "message": 'Invalid Token'
}

Unprocessable Entity
This happens when you did not enter a value. Number to() and Message message() are both required entities.

{
  "success": false,
  "message": 'Unprocessable Entity',
  "errors": {
    "number": [
      0 => 'The message field is required.'
    ],
    "message": [
      0 => 'The number field is required.'
    ]
  }
}

Insufficient credits. Please buy more credit to use this service.
This happens when you already used all of your SMS credits.

{
  "success": false,
  "message": 'Insufficient credits. Please buy more credit to use this service.'
}

laravel-txtbox's People

Contributors

woenel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.