How to use SnapeBot

SnapeBot is really easy to use once you have understood how to do it. Here is a little guide to learn how to use SnapeBot.

$SnapeBot structure

A SnapeBot, technically \neneone\SnapeBot\SnapeBot is structured in the following way:

Additionally, you can find variables at $SnapeBot->variableName following this explanation.

When creating a bot, I suggest you to create different files for a better legibility, but in this example I’ll put all in one single file. You can find multifiles examples in the Examples folder.

require_once __DIR__.'/vendor/autoload.php';
# Use the following line if you've installed SnapeBot with semiAutoloader.php
# require_once __DIR__.'/semiAutoloader.php';

$settings = [
  'database' => [
    'host' => 'localhost',
    'dbName' => 'myAwesomeDatabase',
    'username' => 'root',
    'password' => 'MyAwesomePassword',
    'tableName' => 'MyAwesomeBot',
  ],
  'botUsername' => 'myAwesomeBot',
  'firstRun' => false,
];

$update = json_decode(file_get_contents('php://input'), true); #Get the update
$bot = new \neneone\SnapeBot\SnapeBot('Bot Token', $update, $settings); #Create an instance of SnapeBot

if (isset($bot->msg) && $bot->msg == '/start') { #Check if there is a message, and if it's "/start"
    $bot->API->sendMessage($bot->chatID, 'Hello World!'); #Send the "Hello Wolrd!" message
}

This examples creates a bot that, when the /start command is sent, says Hello World!.

Next section