Overview

Namespaces

  • Baidu
    • Duer
      • Botsdk
        • Card
        • Directive
          • AppLauncher
          • AudioPlayer
          • WebBrowser
        • Plugins

Classes

  • Baidu\Duer\Botsdk\Bot
  • Baidu\Duer\Botsdk\Card\BaseCard
  • Baidu\Duer\Botsdk\Card\ImageCard
  • Baidu\Duer\Botsdk\Card\ListCard
  • Baidu\Duer\Botsdk\Card\ListCardItem
  • Baidu\Duer\Botsdk\Card\StandardCard
  • Baidu\Duer\Botsdk\Card\TextCard
  • Baidu\Duer\Botsdk\Certificate
  • Baidu\Duer\Botsdk\Directive\AppLauncher\LaunchApp
  • Baidu\Duer\Botsdk\Directive\AudioPlayer\Play
  • Baidu\Duer\Botsdk\Directive\AudioPlayer\Stop
  • Baidu\Duer\Botsdk\Directive\BaseDirective
  • Baidu\Duer\Botsdk\Directive\WebBrowser\LaunchBrowser
  • Baidu\Duer\Botsdk\Intercept
  • Baidu\Duer\Botsdk\Log
  • Baidu\Duer\Botsdk\Nlu
  • Baidu\Duer\Botsdk\Plugins\DuerSessionIntercept
  • Baidu\Duer\Botsdk\Request
  • Baidu\Duer\Botsdk\Response
  • Baidu\Duer\Botsdk\Session

Traits

  • Baidu\Duer\Botsdk\DataObject
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 
<?php
/**
 * Copyright (c) 2017 Baidu, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @desc DuerOS对Bot的请求封装
 * @author ******@baidu.com
 **/
namespace Baidu\Duer\Botsdk;

class Request {
    /**
     * 当前请求的类型,对应request.type
     **/
    private $requestType;

    /**
     * Session
     **/
    private $session;

    /**
     * UIC 用户信息
     **/
    private $arrUserProfile;

    /**
     * NLU
     **/
    private $nlu;

    /**
     * 原始数据
     **/
    private $data;

    /**
     * ??
     **/
    private $backendServiceInfo;


    /**
     * 设备信息。比如闹钟列表
     **/
    private $deviceData;

    /**
     * @desc 返回request 请求体
     * @param null
     * @return array
     **/
    public function getData(){
        return $this->data; 
    }

    /**
     * @desc 返回session实例
     * @param null
     * @return Session
     **/
    public function getSession() {
        return $this->session;
    }

    /**
     * @desc 返回nlu实例
     * @param null
     * @return Nlu
     **/
    public function getNlu(){
        return $this->nlu;
    }
    
    
    /**
     * @deprecated
     * @desc 返回设备信息
     * @param null
     * @return Nlu
     **/
    public function getDeviceData(){
        return $this->deviceData;
    }

    /**
     * 获取设备id
     * @desc 获取设备id
     * @param null
     * @return string
     **/
    public function getDeviceId() {
        return $this->data['context']['System']['device']['deviceId']; 
    }

    /**
     * 获取设备音频播放的状态
     *
     * @desc 获取设备音频播放的状态
     * @param null
     * @return array
     **/
    public function getAudioPlayerContext() {
        return $this->data['context']['AudioPlayer']; 
    }

    /**
     * 获取设备app安装列表
     *
     * @desc 获取设备app安装列表
     * @param null
     * @return array
     **/

    public function getAppLauncherContext() {
        return $this->data['context']['AppLauncher']; 
    }

    /**
     * 获取event请求
     *
     * @desc 返回event request数据
     * @param null
     * @return array
     **/
    public function getEventData() {
        if($this->requestType == 'IntentRequest'
           || $this->isSessionEndedRequest()
           || $this->isLaunchRequest()) {
              return; 
           }

        return $this->data['request'];
    }

    /**
     * @deprecated
     * @param null
     * @return array
     **/
    public function getUserInfo() {
        return $this->data['user_info'];
    }
    
    /**
     * 获取request类型
     *
     * @param null
     * @return string 
     */
    public function getType() {
        return $this->requestType;
    }


    /**
     * 获取用户id
     *
     * @param null
     * @return string
     **/
    public function getUserId() {
        return $this->data['context']['System']['user']['userId']; 
    }

    /**
     * @deprecated
     * @desc 获cuid
     * @param null
     * @return string
     **/
    public function getCuid() {
        return $this->data['cuid'];
    }


    /**
     * 获取query
     * @desc 获取当前请求的query
     *
     * @param null
     * @return string
     **/
    public function getQuery() {
        if($this->requestType == 'IntentRequest') {
            return $this->data['request']['query']['original'];
        }
        return '';
    }


    /**
     * 获取地址
     * @desc 获取当前用户设备的位置信息。具体协议参考连接TODO
     *
     * @param null
     * @return array
     **/
    public function getLocation() {
        if(isset($this->data['context']['System']['user']['userInfo'])) {
            return $this->data['context']['System']['user']['userInfo']['location']; 
        }
    }
    
    /**
     * 是否为调起bot
     *
     * @desc 是否为调起bot请求
     * @param null
     * @return boolean
     **/
    public function isLaunchRequest(){
        return $this->data['request']['type'] == 'LaunchRequest';
    }

    /**
     * @deprecated
     * @param null
     * @return boolean
     **/
    public function isSessionEndRequest(){
        return $this->data['request']['type'] == 'SessionEndedRequest';
    }

    /**
     * 是否为关闭bot请求
     *
     * @param null
     * @return boolean
     **/
    public function isSessionEndedRequest(){
        return $this->isSessionEndRequest();
    }

    /**
     * 获取请求的时间戳
     *
     * @return string
     */
    public function getTimestamp() {
        return $this->data['request']['timestamp'];
    }

    /**
     * 获取log_id
     *
     * @deprecated
     * @param null
     * @return string
     */
    public function getLogId() {
        return $this->data['log_id'];
    }
    
    /**
     * 获取botid
     *
     * @param null
     * @return string
     **/
    public function getBotId() {
        return $this->data['context']['System']['application']['applicationId']; 
    }

    /**
     * 槽位是否填完
     *
     * @desc 填槽型多轮,当槽位补充完整后
     *       如果设置了slot confirm或者intent confirm,这些都执行完成后 
     *       对话状态设置为完成,这个函数判断是否为这个状态。
     * @param null
     * @return boolean
     **/
    public function isDialogStateCompleted(){
        return $this->data['request']['dialogState'] == 'COMPLETED';
    }

    /**
     * 构造函数
     *
     * @param array
     * @return null
     **/
    public function __construct($data) {
        $this->data = $data;
        $this->requestType = $data['request']['type'];
        $this->session = new Session($data['session']);
        if($this->requestType == 'IntentRequest') {
            $this->nlu = new Nlu($data['request']['intents']);
        }
    }
}

API documentation generated by ApiGen