ダウンロード ボットブラデスクトップは、ご自身の個人ボットのためのPCまたはMac
Bot Libre Forum

Sending a chat message to a bot using Bot Libre PHP SDK

による OmarBajunaid 掲載 Oct 11 2023, 17:53

To begin, you should first set up the PHP server and the SDK. Please follow the instructions provided in this post: https://botlibre.com/forum-post?id=47255847

Firstly, ensure you meet these prerequisites:
1. Create an account by visiting https://www.botlibre.com.
2. Retrieve your application ID from your account details.
3. We will be using Brain Bot with the ID: 165, to send and receive a message.

Prior to testing the API, please ensure you have the following: user credentials, password, and your application ID.
To proceed, open the "index.php" file located in Bot Libre PHP SDK and make the following changes:

...
/* Enter your application ID here.
* You can get an application ID from any of the services websites (Bot Libre, Bot Libre for Business)
*/
public static string $applicationId = "your applicatoin id i.e 149384728475...";
...
/**
* Please 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 = "your user id";
public static string $password = "your password";
...

Additionally, you will need to include the bot's ID. This can be achieved through the "testSendChatMessage()" function.

...
//TODO: Set message
$config = new ChatConfig();
$config->message = "hello world!";
$config->instance = "165";
return Main::$connection->chat($config);
...

Note: For other API requests, for example the creation of a new post in a forum, you'll need to provide specific IDs, such as the forum ID.
public static ?string $forumInstanceId = "3344566";


Please ensure you set the appropriate IDs as needed for each request.

Proceeding to testing the api, Once that’s done, we need to start up the PHP server.

Navigate to the directory where the Bot Libre PHP SDK is located using the terminal or command prompt on windows. 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/index.php".


localhost_index.JPG

To proceed with testing, select "post-chat" from the dropdown menu, and then click the "Test" button located next to the dropdown menu.


list_of_requests.JPG

After clicking the "Test" button, closely monitor the API logs to observe the ongoing activities. You can review each POST request for a detailed overview of the activity.


post_chat_response.JPG

These logs can provide valuable insights into the behind-the-scenes operations. To gain a better understanding of the functions and their requirements, please review the remaining functions in the "index.php" file.


Id: 49744563
掲載: Oct 11 2023, 17:53
回答: 0
眺望: 847, 今日の: 2, 週間: 7, 月: 59
0 0 0.0/5