Difference between revisions of "PHP/Multiple Bots"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:SmartBots PHP API}} == Multiple Bots == If you're familiar with Object-Orientated PHP, you've most likely already worked this out, however you can actually hav...")
 
Line 1: Line 1:
{{DISPLAYTITLE:SmartBots PHP API}}
 
 
== Multiple Bots ==
 
== Multiple Bots ==
  
Line 36: Line 35:
 
[[HTTP_API/PHP/Performing_Actions|Prev Section (Performing Actions)]]<div class="floatright">[[HTTP_API/PHP/Available_Actions|Next Section (Available Actions)]]</div>
 
[[HTTP_API/PHP/Performing_Actions|Prev Section (Performing Actions)]]<div class="floatright">[[HTTP_API/PHP/Available_Actions|Next Section (Available Actions)]]</div>
 
{{NavMenu}}
 
{{NavMenu}}
 +
__NOTOC__

Revision as of 08:04, 25 August 2016

Multiple Bots

If you're familiar with Object-Orientated PHP, you've most likely already worked this out, however you can actually have multiple bots interacting with each other at once, in one single script! The below code demonstrates how two bots will IM each other, and then echo their responses to the screen!

<?php
    include("smartbots_api.php"); // Include the SmartBots API file.

    $apiKey = "e40e365171a99nl05bdmd697273b573t"; // SmartBots API Key.

    /* Bot Number 1 */
    $bot1_Name       = "Example Resident"; // The bot's full name.
    $bot1_AccessCode = "KbYpnfa"; // The bot's access code.

    /* Bot Number 2 */
    $bot2_Name       = "Awesome Linden"; // The bot's full name.
    $bot2_AccessCode = "f9xH9oD"; // The bot's access code.

    /* Instansiate Bot 1 */
    $bot1 = new SmartBot(); // Instansiate a new SmartBot class.
    $bot1->setup($apiKey, $bot1_Name, $bot1_AccessCode); // Pass the setup variables to the API.

    /* Instansiate Bot 2 */
    $bot2 = new SmartBot(); // Instansiate a new SmartBot class.
    $bot2->setup($apiKey, $bot2_Name, $bot2_AccessCode); // Pass the setup variables to the API.

    /* Send the IMs */
    $bot1->im($bot2_Name, "Hello bot number two!"); // Send an IM.
    $bot2->im($bot1_Name, "Hello bot number one!"); // Send an IM.

    echo "Bot 1 returned '" . $bot1->response(TRUE) . "'<br>"; // Print the result from Bot 1.
    echo "Bot 2 returned '" . $bot2->response(TRUE) . "'<br>"; // Print the result from Bot 2.
?>
Prev Section (Performing Actions)