Difference between revisions of "PHP/Getting Started"
Line 5: | Line 5: | ||
To begin, you will first need to create a blank .php file and include the 'smartbots_api.php' file. | To begin, you will first need to create a blank .php file and include the 'smartbots_api.php' file. | ||
− | |||
<source lang="php"> | <source lang="php"> | ||
<?php | <?php | ||
Line 12: | Line 11: | ||
Next, we will need to define your [https://www.mysmartbots.com/process/adminbot.html SmartBots Developer API key], your bot's name and [http://www.mysmartbots.com/docs/Bot_access_code access code] so that it's easier to use them later. | Next, we will need to define your [https://www.mysmartbots.com/process/adminbot.html SmartBots Developer API key], your bot's name and [http://www.mysmartbots.com/docs/Bot_access_code access code] so that it's easier to use them later. | ||
− | |||
<source lang="php"> | <source lang="php"> | ||
$apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key. | $apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key. | ||
Line 22: | Line 20: | ||
Now we will create the <source lang="php" enclose="none">$bot</source> variable and instansiate a new <source lang="php" enclose="none">SmartBot() class</source> so that we can begin making our bot function. | Now we will create the <source lang="php" enclose="none">$bot</source> variable and instansiate a new <source lang="php" enclose="none">SmartBot() class</source> so that we can begin making our bot function. | ||
− | |||
<source lang="php"> | <source lang="php"> | ||
$bot = new SmartBot(); // Instansiate a new SmartBot class. | $bot = new SmartBot(); // Instansiate a new SmartBot class. | ||
Line 28: | Line 25: | ||
To let the SmartBots API know what bot we are going to be controlling, we now need to use the <source lang="php" enclose="none">setup()</source> method/function to enter in the variables we created earlier. The setup process returns <source lang="php" enclose="none">TRUE</source> or <source lang="php" enclose="none">FALSE</source>, depending on whether or not it was successful, meaning that you would use it within an 'if' statement if you wanted. | To let the SmartBots API know what bot we are going to be controlling, we now need to use the <source lang="php" enclose="none">setup()</source> method/function to enter in the variables we created earlier. The setup process returns <source lang="php" enclose="none">TRUE</source> or <source lang="php" enclose="none">FALSE</source>, depending on whether or not it was successful, meaning that you would use it within an 'if' statement if you wanted. | ||
− | |||
<source lang="php> | <source lang="php> | ||
$bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API. | $bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API. | ||
+ | </source> | ||
+ | |||
+ | Your SmartBot is now connected to the API and is ready to accept some awesome functions! At the end of this section, your code could look a little something like this: | ||
+ | <source lang="php> | ||
+ | <?php | ||
+ | include("smartbots_api.php"); // Include the SmartBots API file. | ||
+ | |||
+ | $apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key. | ||
+ | $botName = "Example Resident"; // The bot's full name. | ||
+ | $botAccessCode = "KbYpnfa"; // The bot's access code. | ||
+ | |||
+ | $bot = new SmartBot(); // Instansiate a new SmartBot class. | ||
+ | $bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API. | ||
+ | ?> | ||
</source> | </source> | ||
{{NavMenu}} | {{NavMenu}} |
Revision as of 10:14, 20 August 2016
Getting Started
Before following these instructions, please download the source files and place them into your project.
To begin, you will first need to create a blank .php file and include the 'smartbots_api.php' file.
<?php
include("smartbots_api.php"); // Include the SmartBots API file.
Next, we will need to define your SmartBots Developer API key, your bot's name and access code so that it's easier to use them later.
$apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key.
$botName = "Example Resident"; // The bot's full name.
$botAccessCode = "KbYpnfa"; // The bot's access code.
If you're not familiar with Object-Orientated PHP, the next section may look a little strange, however follow the instructions and all should be clear.
Now we will create the $bot
variable and instansiate a new SmartBot() class
so that we can begin making our bot function.
$bot = new SmartBot(); // Instansiate a new SmartBot class.
To let the SmartBots API know what bot we are going to be controlling, we now need to use the setup()
method/function to enter in the variables we created earlier. The setup process returns TRUE
or FALSE
, depending on whether or not it was successful, meaning that you would use it within an 'if' statement if you wanted.
$bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API.
Your SmartBot is now connected to the API and is ready to accept some awesome functions! At the end of this section, your code could look a little something like this:
<?php
include("smartbots_api.php"); // Include the SmartBots API file.
$apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key.
$botName = "Example Resident"; // The bot's full name.
$botAccessCode = "KbYpnfa"; // The bot's access code.
$bot = new SmartBot(); // Instansiate a new SmartBot class.
$bot->setup($apiKey, $botName, $botAccessCode); // Pass the setup variables to the API.
?>