NorthStudio's ChatFramework is a PHP Framework that accelerate your Chatbot building process.
It supports:
- Upload API
- Send API
- Messenger Profile (Basic)
- Retrieve User Profile
Also contain:
- A fast & structured Message Builder
- Easy to modify
Note: You may want to have basic knowledge about Messenger Platform first. Please read Messenger APIs document before using this Framework.
Supporting almost components in Messenger Platform (exept some components soon will be deprecated):
- [Text Message] - A simple text message.
- Generic Template - A simple structured message that includes a title, subtitle, image, and up to three buttons.
- List Template - awesome web-based text editor
- Button Template - great UI boilerplate for modern web apps
- Media Template - Markdown parser done right. Fast and easy to extend.
ChatFramework requires PHP 5+. The installation can easily be done by downloading this repository as zip then extract the folder into your project's directory.
<?php
include "ChatFramework/autoload.php"; // Include the right directory of autoload.php file in Framework's directory
?>
Please take the Page Access Token of your Facebook Fanpage before continuing. If you don't know how to do it, please take it from Facebook Developer Dashboard. Here is initialization script:
<?php
$isHubChallenge = false; // set to true if you want to accept all Hub Challenge validation
$accessToken = "<PLACE_YOUR_PAGE_TOKEN_HERE>";
$bot = new \NorthStudio\ChatFramework($accessToken, $isHubChallenge);
$builder = new \NorthStudio\MessageBuilder();
?>
At the first time you connect your Facebook App with Webhook, there's something called Hub Challenge. It's validation step of Facebook Platform so don't be worry. However, there're some notes for you:
- Webhook's URL must starts with HTTPS.
- You can use any secret key with this Framework, password of Hub Challenge makes no sense.
- Please set the second parameter of Class initialization
$isHubChallenge = true
The generic template is a simple structured message that includes a title, subtitle, image, and up to three buttons. You may also specify a
default_action
object that sets a URL that will be opened in the Messenger webview when the template is tapped.
// Create buttons
$firstButton = $builder->createButton("postback", "Nút 1", "button_1");
$secondButton = $builder->createButton("postback", "Nút 2", "button_2");
$thirdButton = $builder->createButton("postback", "Nút 3", "button_3");
// Default action when user click the message
$defaultAction = $builder->createTemplateDefaultAction('https://www.facebook.com');
// Create Template Element
$templateElement = $builder->createTemplateElement("Tiêu đề", "Tiêu đề con", $defaultAction, [
$firstButton, $secondButton, $thirdButton
], "https://petersfancybrownhats.com/company_image.png");
// Create Template
$genericTemplate = $builder->createGenericTemplate(
$templateElement
);
// Finally, send it to user
$bot->sendMessage(
$userId,
$genericTemplate
);