### Web Driver Installation and Setup Source: https://github.com/botman/docs/blob/master/driver-web.md Instructions on how to install and set up the BotMan Web Driver using Composer or BotMan Studio, and how to load the driver before creating a BotMan instance. ```APIDOC ## Web Driver Installation & Setup ### Description Instructions on how to install and set up the BotMan Web Driver. This driver can be used as a starting point to add BotMan to your website or API. The driver itself receives the incoming requests and responds with a JSON representing the message result. ### Method Composer / Artisan CLI ### Endpoint N/A ### Parameters None ### Request Example ```sh # Using Composer composer require botman/driver-web # Using BotMan Studio php artisan botman:install-driver web ``` ### Response N/A ### Notes If not using BotMan Studio, load the driver before creating the BotMan instance: ```php use BotManDriversWebWebDriver; use BotmanBotManBotManFactory; DriverManager::loadDriver(WebDriver::class); // Create BotMan instance $botman = BotManFactory::create($config); ``` ``` -------------------------------- ### BotMan Studio Installation and Setup (Shell) Source: https://context7.com/botman/docs/llms.txt Installs BotMan Studio, a Laravel integration for BotMan, using Composer. It provides commands to create a new chatbot project, start a development server, and install platform-specific drivers like Facebook, Slack, or Telegram. ```sh # Install BotMan Studio installer globally composer global require "botman/installer" # Create a new BotMan project botman new my-chatbot # Or use Composer create-project composer create-project --prefer-dist botman/studio my-chatbot # Navigate to project and start development server cd my-chatbot php artisan serve # Install platform-specific drivers php artisan botman:install-driver facebook php artisan botman:install-driver slack php artisan botman:install-driver telegram ``` -------------------------------- ### Start Laravel Development Server Source: https://github.com/botman/docs/blob/master/installation.md Starts a simple PHP development server for a BotMan Studio project. This command is used to test the chatbot application locally. ```sh php artisan serve ``` -------------------------------- ### Install Node.js and npm Source: https://github.com/botman/docs/blob/master/web-widget.md Commands to install Node.js and npm on Debian-based systems. Includes installing build essentials and checking versions. ```bash apt-get install build-essential libssl-dev apt-get install nodejs nodejs -v apt-get install npm npm -v ``` -------------------------------- ### Basic BotMan Usage as Standalone PHP Source: https://github.com/botman/docs/blob/master/installation.md Demonstrates the basic usage of BotMan as a standalone Composer dependency. This code snippet shows how to configure drivers, create a BotMan instance, define message listeners, and start the listening process. ```php [ // "token" => "TOKEN" // ] ]; // Load the driver(s) you want to use DriverManager::loadDriver(\\BotMan\\Drivers\\Telegram\\TelegramDriver::class); // Create an instance $botman = BotManFactory::create($config); // Give the bot something to listen for. $botman->hears('hello', function (BotMan $bot) { $bot->reply('Hello yourself.'); }); // Start listening $botman->listen(); ``` -------------------------------- ### Install BotMan Studio Installer Source: https://github.com/botman/docs/blob/master/botman-studio.md Installs the BotMan Studio global installer using Composer. Ensure the Composer vendor bin directory is in your system's PATH. ```sh composer global require "botman/installer" ``` -------------------------------- ### Install Node.js with nvm Source: https://github.com/botman/docs/blob/master/web-widget.md Commands to list available Node.js versions and install a specific version using nvm. ```bash nvm ls-remote nvm use ``` -------------------------------- ### Add Get Started Button to Facebook Messenger Source: https://github.com/botman/docs/blob/master/driver-facebook-messenger.md Configures the 'Get Started' button for a Facebook Messenger bot. This button is displayed on the first interaction and sends a predefined payload. The payload is set in the `config/botman/facebook.php` file, and the button is added via an Artisan command. The bot can then listen for this payload to send a welcome message. ```php 'start_button_payload' => 'YOUR_PAYLOAD_TEXT' ``` ```sh php artisan botman:facebook:AddStartButton ``` ```php $botman->hears('YOUR_PAYLOAD_TEXT', function (BotMan $bot) { // ... }); ``` -------------------------------- ### Install npm and nvm on macOS Source: https://github.com/botman/docs/blob/master/web-widget.md Homebrew commands to install npm and nvm on macOS systems. ```bash brew install npm brew install nvm ``` -------------------------------- ### Web Driver Incoming Request and Response Examples Source: https://github.com/botman/docs/blob/master/driver-web.md Examples of a basic incoming JSON request for the WebDriver and an example response from BotMan. ```APIDOC ## Web Driver Request & Response Examples ### Description Provides examples of a typical incoming JSON request to the WebDriver and an example JSON response from BotMan. ### Method GET or POST (depending on BotMan setup) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **driver** (string) - Required - The driver type, should be 'web' for this driver. - **userId** (string) - Required - The sender of the request, used for conversation management. - **message** (string) - Required - The content of the user's message. ### Request Example ```json { "driver": "web", "userId": "1234", "message": "hi" } ``` ### Response #### Success Response (200) - **status** (integer) - The status code of the response. - **messages** (array) - An array of message objects that BotMan replies. - **type** (string) - The type of message (e.g., 'text'). - **text** (string) - The content of the message. - **attachment** (object|null) - Optional attachment details (e.g., image, button). - **type** (string) - The type of attachment. - **url** (string) - The URL of the attachment. - **title** (string|null) - The title of the attachment. #### Response Example ```json { "status":200, "messages":[ { "type":"text", "text":"I have no idea what you are talking about!", "attachment":{ "type":"image", "url":"https:\/\/botman.io\/img\/logo.png", "title":null } } ] } ``` ``` -------------------------------- ### Install Nexmo Driver with BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-nexmo.md Installs the Nexmo driver using the BotMan Studio Artisan command. This command handles the necessary setup for the driver within a BotMan Studio project. ```sh php artisan botman:install-driver nexmo ``` -------------------------------- ### Install nvm (Node Version Manager) Source: https://github.com/botman/docs/blob/master/web-widget.md Steps to download, inspect, and install nvm using curl and bash. Also covers sourcing the profile to access nvm. ```bash curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh -o install_nvm.sh nano install_nvm.sh bash install_nvm.sh source ~/.profile ``` -------------------------------- ### Install Slack Driver (BotMan Studio) Source: https://github.com/botman/docs/blob/master/driver-slack.md Installs the Slack driver using the BotMan Studio Artisan command. This is a convenient method for Studio users. ```sh php artisan botman:install-driver slack ``` -------------------------------- ### Install Slack Driver (Composer) Source: https://github.com/botman/docs/blob/master/driver-slack.md Installs the BotMan Slack driver using Composer. This is the first step to integrate BotMan with Slack. ```sh composer require botman/driver-slack ``` -------------------------------- ### Install BotMan and Basic Chatbot Instance (PHP) Source: https://context7.com/botman/docs/llms.txt Installs BotMan via Composer and sets up a basic chatbot instance. It loads a specific driver (e.g., Telegram) and defines a simple 'hello' command. This snippet requires the BotMan library and a messaging platform driver. ```php hears('Hi', function (BotMan $bot) { $bot->reply('Hello!'); }); $botman->listen(); } /** * @return */ public function config() { return [ 'dialogflow' => [ 'google_project' => env('GOOGLE_PROJECT_ID'), 'dialogflow_version' => 'v2', 'dialogflow_client_access_token' => env('DIALOGFLOW_CLIENT_ACCESS_TOKEN') ] ]; } /** * @return */ public function tinker() { return botman(IncomingMessage::class); } } ``` -------------------------------- ### Install Twilio Driver with BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-twilio.md Installs the Twilio driver using the BotMan Studio Artisan command. This simplifies the installation process for Studio users. ```shell php artisan botman:install-driver twilio ``` -------------------------------- ### Install BotMan with Composer Source: https://github.com/botman/docs/blob/master/installation.md Installs the BotMan PHP package and its dependencies using Composer. This is the command to use when integrating BotMan into an existing PHP project without BotMan Studio. ```sh composer require botman/botman ``` -------------------------------- ### Install Web Driver with BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-web.md Installs the Web Driver using the BotMan Studio Artisan command. This is the recommended method for users of BotMan Studio. ```sh php artisan botman:install-driver web ``` -------------------------------- ### Create New BotMan Project with Composer Source: https://github.com/botman/docs/blob/master/installation.md Creates a new BotMan project using Composer's create-project command. This method clones the BotMan Studio application and installs all necessary dependencies. ```sh composer create-project --prefer-dist botman/studio ``` -------------------------------- ### Create New BotMan Project with BotMan Studio Source: https://github.com/botman/docs/blob/master/installation.md Creates a new BotMan project using the BotMan Studio installer. This command sets up a new directory with a fresh Laravel application and BotMan, including advanced development tools. ```sh botman new ``` -------------------------------- ### Install Hangouts Driver using BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-hangouts-chat.md This command installs the Hangouts driver for BotMan when using BotMan Studio. It simplifies the driver installation process within the Studio environment. ```shell php artisan botman:install-driver hangouts ``` -------------------------------- ### Install Twilio Driver for BotMan Source: https://github.com/botman/docs/blob/master/driver-twilio.md Installs the Twilio driver using Composer for BotMan projects. This is the first step to enable Twilio integration. ```shell composer require botman/driver-twilio ``` -------------------------------- ### Create New BotMan Studio Project Source: https://github.com/botman/docs/blob/master/botman-studio.md Creates a new BotMan Studio project with the specified directory name. This command automatically installs BotMan and its dependencies. ```sh botman new weatherbot ``` -------------------------------- ### Install BotMan Web Driver (Composer) Source: https://github.com/botman/docs/blob/master/driver-web.md Installs the BotMan Web Driver using Composer. This is the first step to integrate BotMan into your web application. ```sh composer require botman/driver-web ``` -------------------------------- ### Install Telegram Driver via Composer Source: https://github.com/botman/docs/blob/master/driver-telegram.md Installs the BotMan Telegram Driver using Composer. This is the first step to integrate Telegram with BotMan. ```sh composer require botman/driver-telegram ``` -------------------------------- ### Build the BotMan Web Widget Source: https://github.com/botman/docs/blob/master/web-widget.md Commands to navigate to the widget directory and install necessary build tools and dependencies using npm and bower, followed by the build script. ```bash cd npm install -g grunt-cli npm install -g webpack npm install -g bower npm install -g gulp npm install preact npm install npm run-script build ``` -------------------------------- ### List Available BotMan Drivers Source: https://github.com/botman/docs/blob/master/botman-studio.md Lists all core drivers available and currently installed in your BotMan Studio application using an Artisan command. ```sh php artisan botman:list-drivers ``` -------------------------------- ### Install Telegram Driver via BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-telegram.md Installs the Telegram Driver using the BotMan Studio Artisan command. This is the recommended method when using BotMan Studio. ```sh php artisan botman:install-driver telegram ``` -------------------------------- ### Install Facebook Driver (Composer) Source: https://github.com/botman/docs/blob/master/driver-facebook-messenger.md Installs the Facebook driver using Composer. This is the first step for integrating BotMan with Facebook Messenger. ```sh composer require botman/driver-facebook ``` -------------------------------- ### Install New BotMan Driver Source: https://github.com/botman/docs/blob/master/botman-studio.md Installs a new BotMan messaging driver using the `botman:install-driver` Artisan command, followed by the driver name. This performs a `composer require` and publishes configuration files. ```sh php artisan botman:install-driver facebook ``` -------------------------------- ### Install Bot Framework Driver (BotMan Studio) Source: https://github.com/botman/docs/blob/master/driver-ms-bot-framework.md Installs the Bot Framework driver using the BotMan Studio artisan command. This is the recommended method when using BotMan Studio. ```sh php artisan botman:install-driver botframework ``` -------------------------------- ### Install Bot Framework Driver (Composer) Source: https://github.com/botman/docs/blob/master/driver-ms-bot-framework.md Installs the Bot Framework driver using Composer. This is the initial step to integrate the driver into your project. ```sh composer require botman/driver-botframework ``` -------------------------------- ### Install Nexmo Driver via Composer Source: https://github.com/botman/docs/blob/master/driver-nexmo.md Installs the Nexmo driver for BotMan using Composer. This is the first step to integrate Nexmo messaging capabilities. ```sh composer require botman/driver-nexmo ``` -------------------------------- ### Load Cisco Spark Driver (Manual Setup) Source: https://github.com/botman/docs/blob/master/driver-cisco-spark.md Loads the Cisco Spark driver manually before creating the BotMan instance. This method is used when not utilizing BotMan Studio. ```php DriverManager::loadDriver(BotManDriversCiscoSparkCiscoSparkDriver::class); // Create BotMan instance BotManFactory::create($config); ``` -------------------------------- ### Basic BotMan Test Example Source: https://github.com/botman/docs/blob/master/testing.md A fundamental test case demonstrating how to simulate a user receiving a message and asserting a reply. This is the basic structure for testing bot interactions. ```PHP public function testBasicTest() { $this->bot ->receives('Hi') ->assertReply('Hello!'); } ``` -------------------------------- ### Install Cisco Spark Driver with Composer Source: https://github.com/botman/docs/blob/master/driver-cisco-spark.md Installs the Cisco Spark driver using Composer. This is the first step to integrate Cisco Spark with BotMan. ```shell composer require botman/driver-cisco-spark ``` -------------------------------- ### Install Hangouts Driver using Composer Source: https://github.com/botman/docs/blob/master/driver-hangouts-chat.md This command installs the Hangouts driver for BotMan using Composer. It's a prerequisite for integrating Hangouts Chat with your BotMan application. ```shell composer require botman/driver-hangouts ``` -------------------------------- ### Install Cisco Spark Driver with BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-cisco-spark.md Installs the Cisco Spark driver using the BotMan Studio Artisan command. This is a convenient way to add drivers when using BotMan Studio. ```shell php artisan botman:install-driver cisco-spark ``` -------------------------------- ### Install WeChat Driver using BotMan Studio (Artisan) Source: https://github.com/botman/docs/blob/master/driver-wechat.md This Artisan command is used within BotMan Studio to install the WeChat driver. It simplifies the integration process for Studio users. ```sh php artisan botman:install-driver wechat ``` -------------------------------- ### Install HipChat Driver with BotMan Studio Source: https://github.com/botman/docs/blob/master/driver-hipchat.md Installs the HipChat driver using the BotMan Studio Artisan command. This simplifies the integration process for users of BotMan Studio. ```sh php artisan botman:install-driver hipchat ``` -------------------------------- ### Web Driver Configuration for BotManFactory Source: https://github.com/botman/docs/blob/master/driver-web.md Example configuration for the BotManFactory to specify driver matching data. This ensures BotMan correctly identifies incoming requests for the 'web' driver. ```php [ 'web' => [ 'matchingData' => [ 'driver' => 'web', ], ] ] ``` -------------------------------- ### Listen for Files in PHP Source: https://github.com/botman/docs/blob/master/receiving-additional-content.md This example demonstrates listening for general file uploads using the `receivesFiles` method. Similar to other attachments, files are received as an array of `File` objects, from which you can retrieve the URL and payload. ```php use BotMan\BotMan\Messages\Attachments\File; $bot->receivesFiles(function($bot, $files) { foreach ($files as $file) { $url = $file->getUrl(); // The direct url $payload = $file->getPayload(); // The original payload } }); ``` -------------------------------- ### Install WeChat Driver using Composer Source: https://github.com/botman/docs/blob/master/driver-wechat.md This command installs the WeChat driver for BotMan using Composer. It's the first step in integrating WeChat functionality into your BotMan project. ```sh composer require botman/driver-wechat ``` -------------------------------- ### Realtime API Bot Logic (PHP) Source: https://github.com/botman/docs/blob/master/driver-slack.md Example PHP script for using the Slack Realtime API with BotMan. It requires the 'mpociot/slack-client' package and sets up event listeners for bot messages. ```php [ 'token' => 'YOUR-SLACK-BOT-TOKEN', ], ], $loop); $botman->hears('keyword', function($bot) { $bot->reply('I heard you! :)'); }); $botman->hears('convo', function($bot) { $bot->startConversation(new ExampleConversation()); }); $loop->run(); ``` -------------------------------- ### Start BotMan Conversation with PHP Source: https://github.com/botman/docs/blob/master/conversations.md Initiates a new conversation flow within a BotMan keyword callback. This method requires a conversation class that extends BotMan's abstract Conversation class. Ensure a persistent cache driver is configured if not using BotMan Studio. ```php $botman->hears('Hello', function($bot) { $bot->startConversation(new OnboardingConversation); }); ``` -------------------------------- ### Example Incoming JSON Request for Web Driver Source: https://github.com/botman/docs/blob/master/driver-web.md A basic and valid JSON request structure for the BotMan Web Driver. This format is used to send user messages to the BotMan application. ```json { "driver": "web", "userId": "1234", "message": "hi" } ``` -------------------------------- ### Load Driver and Create BotMan Instance - PHP Source: https://github.com/botman/docs/blob/master/drivers.md This snippet demonstrates how to load a custom driver and initialize BotMan. It uses `DriverManager::loadDriver` to register the driver and `BotManFactory::create` to instantiate BotMan with the application's configuration. ```php use BotMan\BotMan\BotManFactory; use BotMan\BotMan\Drivers\DriverManager; DriverManager::loadDriver(FacebookDriver::class); BotManFactory::create(config('botman')); ``` -------------------------------- ### Ask Questions with Buttons and Patterns (PHP) Source: https://context7.com/botman/docs/llms.txt Shows how to create interactive questions with buttons and implement pattern-based responses within BotMan conversations. Requires BotMan library. ```php fallback('Unable to create a new database') ->callbackId('create_database') ->addButtons([ Button::create('Of course')->value('yes'), Button::create('Hell no!')->value('no'), ]); $this->ask($question, function (Answer $answer) { if ($answer->isInteractiveMessageReply()) { $selectedValue = $answer->getValue(); // 'yes' or 'no' $selectedText = $answer->getText(); // 'Of course' or 'Hell no!' } }); } // Structured questions with patterns public function askNextStep() { $this->ask('Shall we proceed? Say YES or NO', [ [ 'pattern' => 'yes|yep', 'callback' => function () { $this->say('Okay - we'll keep going'); } ], [ 'pattern' => 'nah|no|nope', 'callback' => function () { $this->say('PANIC!! Stop the engines NOW!'); } ] ]); } ?> ``` -------------------------------- ### Install HipChat Driver with Composer Source: https://github.com/botman/docs/blob/master/driver-hipchat.md Installs the HipChat driver for BotMan using Composer. This is the initial step for integrating HipChat functionality into your BotMan project. ```sh composer require botman/driver-hipchat ``` -------------------------------- ### Install Amazon Alexa Driver (Composer) Source: https://github.com/botman/docs/blob/master/driver-amazon-alexa.md Installs the Amazon Alexa driver using Composer. This is the first step for integrating Alexa with BotMan. ```sh composer require botman/driver-amazon-alexa ``` -------------------------------- ### Load Slack Driver and Create BotMan Instance (PHP) Source: https://github.com/botman/docs/blob/master/driver-slack.md Loads the Slack driver and creates a BotMan instance with a Slack token. This is used when not using BotMan Studio. ```php use BotMan\Drivers\Slack\SlackDriver; use BotMan\BotMan\BotManFactory; use BotMan\Drivers\DriverManager; DriverManager::loadDriver(SlackDriver::class); // Create BotMan instance $config = [ 'slack' => [ 'token' => 'YOUR-SLACK-BOT-TOKEN' ] ]; BotManFactory::create($config); ``` -------------------------------- ### Load Nexmo Driver and Create BotMan Instance (No Studio) Source: https://github.com/botman/docs/blob/master/driver-nexmo.md Loads the Nexmo driver and creates a BotMan instance when not using BotMan Studio. Requires manual driver loading before BotManFactory::create(). ```php DriverManager::loadDriver(BotManDriversNexmoNexmoDriver::class); // Create BotMan instance BotManFactory::create($config); ``` -------------------------------- ### Applying Custom Matching Middleware in PHP Source: https://github.com/botman/docs/blob/master/middleware.md Demonstrates how to apply a custom matching middleware to BotMan commands, either individually using the `middleware` method or to a group of commands using the `group` method. This ensures commands only respond to specific conditions. ```php $middleware = new CustomMatchingMiddleware(); // Let single command use this matching middleware $botman->hears('keyword', function ($bot) { // })->middleware($middleware); // Let multiple commands use this matching middleware $botman->group(['middleware' => $middleware], function ($botman) { $botman->hears('command one', function ($bot) { }); $botman->hears('command two', function ($bot) { }); }); ``` -------------------------------- ### Example BotMan Web Driver JSON Response Source: https://github.com/botman/docs/blob/master/driver-web.md An example of a JSON response structure from BotMan. It includes a 'messages' array containing the chatbot's replies and any attachments. ```json { "status":200, "messages":[ { "type":"text", "text":"I have no idea what you are talking about!", "attachment":{ "type":"image", "url":"https:\/\/botman.io\/img\/logo.png", "title":null } } ] } ``` -------------------------------- ### Create Conversations with BotMan (PHP) Source: https://context7.com/botman/docs/llms.txt Illustrates how to build multi-step interactive conversations using BotMan's Conversation class, including state management for user information. Requires BotMan library. ```php ask('Hello! What is your firstname?', function(Answer $answer) { $this->firstname = $answer->getText(); $this->say('Nice to meet you ' . $this->firstname); $this->askEmail(); }); } public function askEmail() { $this->ask('One more thing - what is your email?', function(Answer $answer) { $this->email = $answer->getText(); $this->say('Great - that is all we need, ' . $this->firstname); }); } public function run() { $this->askFirstname(); } } // Start the conversation $botman->hears('Hello', function($bot) { $bot->startConversation(new OnboardingConversation); }); // Originate conversation programmatically $botman->startConversation(new OnboardingConversation(), 'my-recipient-user-id', TelegramDriver::class); ?> ``` -------------------------------- ### Install Amazon Alexa Driver (BotMan Studio) Source: https://github.com/botman/docs/blob/master/driver-amazon-alexa.md Installs the Amazon Alexa driver using the BotMan Studio Artisan command. This simplifies the integration process for Studio users. ```sh php artisan botman:install-driver amazon-alexa ``` -------------------------------- ### Create BotMan Studio Project with Composer Source: https://github.com/botman/docs/blob/master/botman-studio.md Alternative method to create a new BotMan Studio project using Composer's create-project command. This achieves the same result as the `botman new` command. ```sh composer create-project --prefer-dist botman/studio weatherbot ``` -------------------------------- ### Create Slack Interactive Menus with PHP Source: https://context7.com/botman/docs/llms.txt This snippet demonstrates how to create various interactive menus in Slack using BotMan's PHP SDK. It covers custom dropdowns, selecting from team members, channels, and conversations. Ensure the Slack driver is configured for these features. ```php callbackId('game_selection') ->addAction( Menu::create('Pick a game...') ->name('games_list') ->options([ ['text' => 'Hearts', 'value' => 'hearts'], ['text' => 'Bridge', 'value' => 'bridge'], ['text' => 'Poker', 'value' => 'poker'], ]) ); $this->ask($question, function (Answer $answer) { $selectedOptions = $answer->getValue(); }); // Select from team members $question = Question::create('Who wins the prize?') ->callbackId('select_users') ->addAction( Menu::create('Who should win?') ->name('winners_list') ->chooseFromUsers() ); // Select from channels $question = Question::create('Nominate the channel of the week') ->callbackId('select_channel') ->addAction( Menu::create('Which channel?') ->name('channels_list') ->chooseFromChannels() ); // Select from conversations $question = Question::create('Start a conversation') ->callbackId('select_conversation') ->addAction( Menu::create('Who did you talk to last?') ->name('conversations_list') ->chooseFromConversations() ); ``` -------------------------------- ### Start Nested BotMan Conversation in PHP Source: https://github.com/botman/docs/blob/master/conversations.md Allows starting a new conversation from within an existing conversation's callback. This is useful for chaining related conversation flows. The `bot` property of the current conversation instance is used to initiate the new conversation. ```php public function askEmail() { $this->ask('One more thing - what is your email?', function(Answer $answer) { // Save result $this->email = $answer->getText(); $this->say('Great - that is all we need, '.$this->firstname); $this->bot->startConversation(new FavouriteLunchConversation()); }); } ``` -------------------------------- ### Send Low-Level API Request to Messaging Service (PHP) Source: https://github.com/botman/docs/blob/master/sending.md Provides an example of sending a low-level API request directly to a messaging service using the `sendRequest` method. This is useful when BotMan's core functionalities do not cover specific native API methods. The example shows sending a sticker via the Telegram API. ```php // Calling the sendSticker API for Telegram $botman->hears('sticker', function($bot) { $bot->sendRequest('sendSticker', [ 'sticker' => '1234' ]) }); ``` -------------------------------- ### Check Driver Configuration - PHP Source: https://github.com/botman/docs/blob/master/drivers.md The `isConfigured` method determines if the driver is ready for use by checking for essential configuration, such as an API token. It returns a boolean value, `true` if configured, `false` otherwise. ```php /** * @return bool */ public function isConfigured() { return !empty($this->config->get('token')); } ``` -------------------------------- ### Get Driver Storage Instance - PHP Source: https://github.com/botman/docs/blob/master/storing-information.md Retrieves the driver-specific storage instance. This storage is restricted to the current messaging service and can store service-related information. ```php $storage = $botman->driverStorage(); ``` -------------------------------- ### NLP Data Structure Example Source: https://github.com/botman/docs/blob/master/nlp.md Illustrates the structured data format (intents and entities) that NLP tools extract from user sentences, which BotMan can then process. ```javascript { "intent": "create_meeting", "entities": { "name" : "Dinner with Nicole", "invitees" : ["Nicole"], "time": "2017-02-05 20:00:00" } } ``` -------------------------------- ### Implement and Apply Captured Middleware in PHP Source: https://github.com/botman/docs/blob/master/middleware.md Shows how to create a custom 'captured' middleware class in PHP for processing user answers within a conversation flow. It also details how to apply this middleware globally to the BotMan instance before listening for messages. ```php use BotMan\BotMan\Interfaces\Middleware\Captured; use BotMan\BotMan\BotMan; use BotMan\BotMan\Messages\Incoming\IncomingMessage; class CustomCapturedMiddleware implements Captured { /** * Handle a captured message. * * @param IncomingMessage $message * @param callable $next * @param BotMan $bot * * @return mixed */ public function captured(IncomingMessage $message, $next, BotMan $bot) { $message->addExtras('custom_message_information', 'my custom value'); return $next($message); } } // Applying the middleware $middleware = new CustomCapturedMiddleware(); $botman->middleware->captured($middleware); ``` -------------------------------- ### Handle Incoming Twilio Calls Source: https://github.com/botman/docs/blob/master/driver-twilio.md Listens for the incoming call event from the Twilio driver and starts a conversation. This allows the chatbot to respond to phone calls. ```php $botman->on(TwilioVoiceDriver::INCOMING_CALL, function($payload, $bot) { $bot->startConversation(new ExampleConversation); }); ``` -------------------------------- ### Utilize BotMan's Storage System for Persistence Source: https://context7.com/botman/docs/llms.txt This PHP snippet illustrates how to use BotMan's built-in storage to persist data for users, channels, and drivers. It covers saving, finding, and deleting user-specific information. It also mentions the availability of channel and driver storage. Input involves commands to save, retrieve, and forget user data; output confirms the actions or provides the retrieved data. ```php hears('save my name as {name}', function($bot, $name) { // Write to user storage $bot->userStorage()->save([ 'name' => $name ]); $bot->reply('Name saved!'); }); $botman->hears('what is my name', function($bot) { // Read from user storage $userinfo = $bot->userStorage()->find($bot->getUser()->getId()); $name = $userinfo->get('name'); $bot->reply("Your name is: " . $name); }); $botman->hears('forget me', function($bot) { // Delete from storage $bot->userStorage()->delete(); $bot->reply('Your information has been deleted.'); }); // Channel and driver storage $channelStorage = $botman->channelStorage(); $driverStorage = $botman->driverStorage(); ``` -------------------------------- ### Ask Simple Text Question - PHP Source: https://github.com/botman/docs/blob/master/conversations.md Asks the user a simple text question and processes their response. This is the most straightforward way to get text input from a user. ```php // ...inside the conversation object... public function askMood() { $this->ask('How are you?', function (Answer $response) { $this->say('Cool - you said ' . $response->getText()); }); } ``` -------------------------------- ### Get Channel Storage Instance - PHP Source: https://github.com/botman/docs/blob/master/storing-information.md Retrieves the channel-specific storage instance. This is useful for storing information related to messaging channels like Slack or Telegram groups. ```php $storage = $botman->channelStorage(); ``` -------------------------------- ### Sending Slack Channel Selection Menu with BotMan Source: https://github.com/botman/docs/blob/master/driver-slack.md Illustrates how to create a Slack menu for users to select one of their team's channels using BotMan's Menu::create()->chooseFromChannels(). The selected channel value is retrieved using $answer->getValue(). ```php Inside your conversation $question = Question::create('It\'s time to nominate the channel of the week') ->callbackId('select_channel') ->addAction( Menu::create('Which channel changed your life this week?') ->name('channels_list') ->chooseFromChannels() ); $this->ask($question, function (Answer $answer) { $selectedOptions = $answer->getValue(); }); ``` -------------------------------- ### Get User Storage Instance - PHP Source: https://github.com/botman/docs/blob/master/storing-information.md Retrieves the user-specific storage instance from the BotMan manager. This allows storing and accessing data unique to the current chatbot user. ```php $storage = $botman->userStorage(); ``` -------------------------------- ### Web Driver Configuration Source: https://github.com/botman/docs/blob/master/driver-web.md Details on configuring the Web Driver, specifically the `matchingData` to ensure BotMan detects incoming requests for the 'web' driver. ```APIDOC ## Web Driver Configuration ### Description Configuration options for the Web Driver, focusing on `matchingData` to correctly identify incoming requests. ### Method Configuration File ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body N/A ### Request Example Configuration snippet for `config/botman/web.php` (if using BotMan Studio): ```php [ 'web' => [ 'matchingData' => [ 'driver' => 'web', ], ] ] ``` ### Response N/A ### Notes The `driver` attribute in the incoming request must match the value specified in `matchingData` for the Web Driver to process the request. ```