Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
vbot
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 02b65c4e
authored
Jan 18, 2017
by
HanSon
Committed by
GitHub
Jan 18, 2017
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #5 from HanSon/dev
修改文档
2 parents
b2be8fa4
6cab8c20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
17 deletions
README.md
example/index.php
README.md
View file @
02b65c4
...
...
@@ -36,22 +36,33 @@ require_once __DIR__ . './../vendor/autoload.php';
use Hanson\Vbot\Foundation\Vbot;
use Hanson\Robot\Message\Message;
use Hanson\Robot\Message\Text;
$robot = new Vbot([
'tmp' => '/path/to/tmp/', # 用于生成登录二维码以及文件保存
'debug' => true # 用于是否输出用户组的json
]);
$robot->server->setMessageHandler(function($message){
if($message->type === 'Text'){
$url = 'http://www.tuling123.com/openapi/api';
// 图灵自动回复
function reply($str){
return http()->post('http://www.tuling123.com/openapi/api', [
'key' => '1dce02aef026258eff69635a06b0ab7d',
'info' => $str
], true)['text'];
$result = http()->post($url, [
'key' => 'your tuling api key',
'info' => $message->content
], true);
}
return $result['text'];
$robot->server->setMessageHandler(function($message){
// 文字信息
if ($message instanceof Text) {
/** @var $message Text */
// 联系人自动回复
if ($message->fromType === 'Contact') {
return reply($message->content);
// 群组@我回复
} elseif ($message->fromType === 'Group' && $message->isAt) {
return reply($message->content);
}
}
});
...
...
example/index.php
View file @
02b65c4
...
...
@@ -30,6 +30,15 @@ $robot = new Vbot([
'debug'
=>
true
]);
// 图灵自动回复
function
reply
(
$str
){
return
http
()
->
post
(
'http://www.tuling123.com/openapi/api'
,
[
'key'
=>
'1dce02aef026258eff69635a06b0ab7d'
,
'info'
=>
$str
],
true
)[
'text'
];
}
$robot
->
server
->
setMessageHandler
(
function
(
$message
)
use
(
$path
)
{
/** @var $message Message */
...
...
@@ -45,17 +54,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
/** @var $message Text */
// 联系人自动回复
if
(
$message
->
fromType
===
'Contact'
)
{
return
http
()
->
post
(
'http://www.tuling123.com/openapi/api'
,
[
'key'
=>
'1dce02aef026258eff69635a06b0ab7d'
,
'info'
=>
$message
->
content
],
true
)[
'text'
];
return
reply
(
$message
->
content
);
// 群组@我回复
}
elseif
(
$message
->
fromType
===
'Group'
&&
$message
->
isAt
)
{
return
http
()
->
post
(
'http://www.tuling123.com/openapi/api'
,
[
'key'
=>
'1dce02aef026258eff69635a06b0ab7d'
,
'info'
=>
$message
->
content
],
true
)[
'text'
];
return
reply
(
$message
->
content
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment