socola/sdk-php-chatfuel-socola

为Facebook Chatfuel聊天机器人使用的性别JSON

v1.1.1 2018-02-20 00:45 UTC

This package is auto-updated.

Last update: 2024-09-29 05:14:49 UTC


README

SDK Php Chatfue Socola
使用PHP生成Chatfuel机器人的JSON

创建机器人

use Socola\Chatfuel;
$bot = new Chatfuel();

发送文本

$text = 'Socola';
$texts = [$text, $text, $text, $text];
$bot->sendText($text);
$bot->sendText($texts);

发送图片

$image = 'http://i.imgur.com/luWlRwV.jpg';
$images = [
	'http://i.imgur.com/luWlRwV.jpg',
	'http://i.imgur.com/luWlRwV.jpg'
];
$bot->sendImage($image);
$bot->sendImage(images);

发送文件

$file = 'https://01b02091.ngrok.io/test.pdf';
$files = array(
	'https://01b02091.ngrok.io/test.pdf',
	'https://01b02091.ngrok.io/test.pdf'
);
$bot->sendFile($file);
$bot->sendFile($files);

发送音频

$audio = 'https://01b02091.ngrok.io/test.mp3';
$audios = [
	'https://01b02091.ngrok.io/test.mp3',
	'https://01b02091.ngrok.io/test.mp3'
];
$bot->sendAudio($audio);
$bot->sendAudio($audios);

创建按钮

创建指向URL的按钮

$title = "button to url";
$url = "https://#";
$buttonToURL = $bot->createButtonToURL($title, $url, $setAttributes = Null);

创建指向块(Block)的按钮

$title = "button to block";
$block = "re-start";
$buttonToBlock = $bot->createButtonToBlock($title, $block, $setAttributes = Null);

创建分享按钮

$buttonShare = $bot->createButtonShare();

创建电话按钮

$phoneNumber = '096******5';
$buttonCall  = $bot->createButtonCall($phoneNumber, $title = 'Call');

创建快速回复按钮

$block = 're-start';
$blocks = [
	'play',
	'pause'
];
$bot->createButtonQuickReply($title, $block);
$bot->createButtonQuickReply($title, $blocks);

发送带有一个或多个按钮的文本卡片(最多3个按钮)

$text = 'this is text card';
$uttons = [
	$buttonToURL,
	$buttonToBlock,
	$buttonShare
];
$bot->sendTextCard($text, $button);
$bot->sendTextCard($text, $buttons);

创建元素

$title    = 'this is element';
$image    = 'http://i.imgur.com/luWlRwV.jpg';
$subTitle = 'this is sub title';
$element  = $bot->createElement($title, $image, $subTitle, $button_or_arrayButtons);
$arrayElements = array(
	$element1,
	$element2
);

发送相册

$bot->sendGallery($element_or_arrayElements);

发送列表模板(至少2个元素)

您可以在“top_element_style”类型之间切换“large”和“compact”。

$topElementStyle = 'large';
$bot->sendList($arrayElements, $topElementStyle);