Skip to main content

📘 The Basics

Here's an example of getMe() API method you can use to test your bot's auth token. Returns basic information about the bot in form of a User object.

See getMe docs for more details.

Standalone

require __DIR__.'/vendor/autoload.php';

use EFive\Bale\Api;

$bale = new Api('YOUR BOT TOKEN');
$response = $bale->getMe();

Laravel

Using Facade

use EFive\Bale\Laravel\Facades\Bale;

$response = Bale::getMe();

Using Service Container

Here's an example using Laravel's service container aka dependency injection.

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use EFive\Bale\Api;

class BotController extends Controller
{
protected $bale;

/**
* Create a new controller instance.
*
* @param Api $bale
*/
public function __construct(Api $bale)
{
$this->bale = $bale;
}

/**
* Show the bot information.
*/
public function show()
{
$response = $this->bale->getMe();

return $response;
}
}

Handling Response

Bale Bot API responses in the SDK are represented as PHP objects. Bale Bot SDK supports all available types of response objects with various helpful methods. In addition, all the related objects of an object are also automatically mapped to the appropriate PHP response object.

In the above example, getMe() returns a User object.

So we can retrieve the object values like so:

$botId = $response->getId();
$firstName = $response->getFirstName();
$username = $response->getUsername();

Additional Information

Bale Bot SDK takes advantage of the amazing Laravel Collection API to automatically map the data.

So it's a lot easier to work with the array of data. Supports all the methods listed on the official docs.