微赞--图灵机器人插件流程分析
来源:
厦门点燃未来网络科技有限公司 发布时间:
2017-09-28 18:41
目录结构如下
template内部包含了所有的静态html文件
module.php 聊天机器人模块定义, 主要是实现模块配置自定义, 保存
processor.php 处理用户发送给公众号的消息
公众号消息处理
用户在公众号发送的消息,会走processor.php 的respond方法:
<?php /** * 聊天机器人模块处理程序 * */ defined('IN_IA') or exit('Access Denied'); class Idou_chatModuleProcessor extends WeModuleProcessor { public function respond() { $config = $this->module['config']; $config['enter_tip'] || $config['enter_tip'] = '你想聊点什么呢'; $config['keep_time'] || $config['keep_time'] = 300; $config['exit_keyword'] || $config['exit_keyword'] = '退出'; $config['exit_tip'] || $config['exit_tip'] = '下次无聊的时候可以再找我聊天哦'; if ($this->message['msgtype'] == 'voice') { if ($config['can_voice'] == '1') { $content = $this->message['recognition']; // 语音识别,直接开启机器人聊天模式 $reply = $this->turingAPI($content); if (is_array($reply)) { return $this->respNews($reply); } else { return $this->respText($reply); } } } else { $content = $this->message['content']; // 通过消息上下文机制与机器人展开聊天 if (!$this->inContext) { $reply = $config['enter_tip']; $this->beginContext($config['keep_time']); // 5分钟后自动退出上下文模式 } else { if ($content == $config['exit_keyword']) { $reply = $config['exit_tip']; $this->endContext(); } else { $reply = $this->turingAPI($content); } } if (is_array($reply)) { return $this->respNews($reply); } else { return $this->respText($reply); } } } }
2:template/setting.html是该模块的配置文件
3:module.php的settingsDisplay方法, 指定了配置文件所在的目录位置, 内部也处理了配置文件信息的保存
作者: NONO
出处:http://www.cnblogs.com/diligenceday/
企业网站:http://www.idrwl.com/
开源博客:http://www.github.com/sqqihao
QQ:287101329
微信:18101055830
文章出自:
厦门点燃未来网络科技有限公司
http://www.idrwl.com如转载请注明出处!