背景

天猫精灵操作法(十分钟用FAAS给你的天猫精灵增加自定义功能)(1)

实现

注册技能

1. 添加自定义技能『小爱同学』

天猫精灵操作法(十分钟用FAAS给你的天猫精灵增加自定义功能)(2)

2. 在侧边栏"意图" tab 中添加意图

3. 在侧边栏"回复逻辑"中配置回调

服务搭建

  1. 新建一个服务,名字随意
  2. 新建两个函数,分别叫 xiaoai 和 auth ,对应的触发器名字分别为 xiaoai_http, auth_http,用于应答和校验

应答服务

var getjsonBody = require('div/json'); exports.handler = (req, resp, context) => { getJsonBody(req, function (err, data) { if (!data || !data.utterance) { resp.send("post div wrong! " data); } resp.setStatusCode(200); resp.setHeader('content-type', 'application/json'); resp.send(JSON.stringify( { "returnCode": "0", "returnErrorSolution": "", "returnMessage": "", "returnValue": { "reply": `小爱同学,我是天猫精灵`, "resultType": "RESULT", "executeCode": "SUCCESS", "msgInfo": "" } })); }); }

校验服务

exports.handler = (req, resp, context) => { resp.setHeader('content-type', 'text/plain'); resp.send("xxx") }

路径注册

大功告成

Tips

参考资料

,