Bot Libre Forum Sign In : Sign Up

How to use the Bot Libre PHP SDK

by admin posted Apr 27 2023, 13:45

The Bot Libre PHP SDK allows you to easily integrate Bot Libre with a PHP application. Through the SDK to can connect to your bots on Bot Libre, send messages, and train and configure your bots. You can also access Bot Libre analytics and AI services, and other content.

The Bot Libre PHP is for usage from server-side PHP code. Note most web applications will integrate with chat through our JavaScript SDK in the browser.

Setting up PHP for Windows


  1. Download PHP: You can download the PHP from the official PHP website. Used the non thread safe (nts) version 8.2.3 for this tutorial. Download from here https://windows.php.net/download#php-8.2
  2. Installing it should be just extracting the zip file and saving it somewhere, for example I chose the following directory and named the folder: D:\php-8.2.3.

To enable PHP to work properly in Windows, we must edit the system environment variables and set the PATH accordingly:

  1. Open the Start menu and search for "Advanced system settings". Click on the "View advanced system settings" option that appears.
  2. In the System Properties window, click on the "Environment Variables" button.
  3. In the Environment Variables window, scroll down to the "System variables" section and locate the "Path" variable. Click on the "Edit" button.
  4. In the Edit Environment Variable window, click on the "New" button and add the path to your PHP installation directory. For example, if you installed PHP in the "D:\php-8.2.3" directory, add "D:\php-8.2.3" to the list of paths.
  5. Click on the "OK" button to save the changes and close all the windows.
  6. Open a new Command Prompt window or restart any open Command Prompt windows for the changes to take effect.
  7. To test if PHP is working correctly, open a Command Prompt window and run the command "php -v". This should display the version of PHP installed on your system.
Configure PHP: After installation, you may need to configure PHP according to your system requirements. This involves editing the php.ini file to enable or disable certain features, set memory limits, and configure database settings.

Changes to php.ini

There have been some changes made in the 'php.ini' file. This file is used to configure the PHP environment and the changes made to it are described below.

The following changes have been made to the php.ini file:
  • Uncomment: extension=curl
  • Uncomment: extension=openssl
  • Uncomment: extension_dir = "D:\php-8.2.3\ext"
cacert.pem is a file containing trusted root certificates that are used for verifying SSL/TLS connections. When a client makes an HTTPS request to a server, it needs to verify that the server's SSL/TLS certificate is valid and has been issued by a trusted certificate authority (CA).

[curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an ; absolute path. curl.cainfo = "D:\php-8.2.3\cacert.pem" [openssl] ; The location of a Certificate Authority (CA) file on the local filesystem ; to use when verifying the identity of SSL/TLS peers. Most users should ; not specify a value for this directive as PHP will attempt to use the ; OS-managed cert stores in its absence. If specified, this value may still ; be overridden on a per-stream basis via the "cafile" SSL stream context ; option. openssl.cafile="D:\php-8.2.3\cacert.pem"


The cacert.pem file is often used in PHP projects to provide a set of trusted root certificates that can be used by the curl library (which is commonly used for making HTTPS requests).
Clone the Bot Libre PHP SDK by clicking on this link: https://github.com/BotLibre/BotLibre/tree/master/sdk/php.

Before starting the PHP server, we will need to edit the index.php file located in the Bot Libre PHP SDK.
  • Must provide application id, username and password to work.
public static string $applicationId = ""; //Application id /** * Enter your account details. Both your username and password are required. * If you don't have an account yet, you can create one to use. */ public static string $username = ""; public static string $password = "";

Once that’s done, we need to start up the PHP server. Open the Command Prompt on Windows.

Navigate to the directory where the Bot Libre PHP SDK is located. For example, if the Bot Libre PHP SDK is located in the "D:\php-8.2.3" directory, you can navigate to that directory by typing "cd D:\php-8.2.3" and pressing Enter.

Once you are in the PHP SDK directory, you can start the PHP development server by typing the following command:

php -S localhost:8000


This will start the PHP development server on your computer, listening on port 8000. You can then access your PHP application by navigating to "http://localhost:8000";.

See also,
https://www.botlibre.com/forum-post?id=49744563


Id: 47255847
Tags: blog, how to, sdk, php
Posted: Apr 27 2023, 13:45
Updated: Oct 24 2023, 14:40
Replies: 0
Views: 5019, today: 3, week: 33, month: 169