Skip to content

Dexalt142/sendtalk-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SendTalk Laravel

Unofficial TapTalk's SendTalk library for Laravel.

PHPUnit Tests Latest Version Packagist Downloads License

1. Installation

You can install this package through Composer CLI by running this command.

composer require dexalt142/sendtalk

Or you can modify the composer.json file and don't forget to run composer install.

{
    "require": {
        "dexalt142/sendtalk": "1.*"
    }
}

2. Configuration

Before using this package, you need to set your SendTalk API key, you can do this by adding SENDTALK_API_KEY to the .env file.

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

SENDTALK_API_KEY=YOUR_SENDTALK_API_KEY_HERE

...

3. How to Use

To call all available methods, you must call it through the SendTalk Facade Dexalt142\SendTalk\Facades\SendTalk.

3.a. Get message status

<?php

namespace App\Http\Controllers;

use Dexalt142\SendTalk\Facades\SendTalk;

class MessageController {

    public function getMessage() {
        // SendTalk::getMessageStatus($id)
        $message = SendTalk::getMessageStatus('f26ccf7a-d867-b3a4-d333-117ec668718d');
    }

}

If the message is exists, the method above will return a result like this example below, otherwise it will throw an exception.

{
    "status": "read",
    "isPending": false,
    "isSent": true,
    "sentTime": 1653924408488,
    "currency": "IDR",
    "price": 75,
    "createdTime": 1653924407993
}

3.b. Send message

<?php

namespace App\Http\Controllers;

use Dexalt142\SendTalk\Facades\SendTalk;

class MessageController {

    public function sendMessage() {

        // SendTalk::sendTextMessage($phoneNumber, $content)
        $textMessage = SendTalk::sendTextMessage('+6281234567890', 'Foo Bar');

        // SendTalk::sendImageMessage($phoneNumber, $imageUrl, $fileName, $caption = null)
        $imageMessage = SendTalk::sendImageMessage('+6281234567890', 'https://example.com/foobar.png', 'foobar.png', 'Foo Bar');

        // SendTalk::sendOTPMessage($phoneNumber, $content)
        $otpMessage = SendTalk::sendOTPMessage('+6281234567890', 'Foo Bar');
    }

}

If the request was sent, the method above will return the id of the message, otherwise it will throw an exception.