# Third Party Service Interface Invocation

If the system API Can not meet the needs of skill development, the platform also supports developers to configure custom API。

# 1. API To configure

After the service interface call is set up for the robot, it is removed from the OpenAI The back-end to the specified URL Object with configured parameters GET Request. The API backend should, upon receipt of the request, return the JSON Response, in the form of:

{
  "err_code": 0,                // Status code that distinguishes the next action after getting a response
  "data_list": [
    {                           // The current return information needs to be wrapped in `data_list` Inside the unique object
      "param_a": "content_a",   // Parameter that can be filled into the corresponding semantic slot after the response is obtained
      "param_b": "content_b"
    }
  ]
}

Note: You need to add a link to the reponse-header中 , Add Content-Type: application/json Response information, otherwise during the conversation, The robot will not be able to accept interface return values correctly

In addition to getting the user input slot information through the dialog, we also made two changes in each interface call

  1. The following fields have been added to the header of the http request:
Response Headers

HTTP/1.1 200 OK

...

appid: abcdef,
bid: 10809,
requestid: 1234567890123456,
uid: oldadfa33
Header field describe
appid Application ID(string)
bid Robot Unique ID (int)
requestid Request unique identification
uid Unique user identification, weixin situation, such as the Official Account message template, Mini Program is the corresponding application of the user openid
  1. The following fields have been added to the params of the http request:
Request Payload
{

...

"encryptText":"xxxxxxxxxxxxxxx" 
}

encryptText For the right User-unique identifier The result of encryption Message encryption and decryption access guidelines

We use APPID and EncodingAESKey Yes User-unique identifier To encrypt

创建自定义接口

[Decryption mode](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Technical_Plan.html#:: text=%E8%A1%A8%E7%A4%BA%E9%AA%8C%E8%AF%81%E9%80%9A%E8%BF%87%E3%80%82-,%E8%A7%A3%E5%AF%86%E6%96%B9%E5%BC%8F%E5%A6%82%E4%B8%8B%EF%BC%9A,-1.%20aes_msg% 3DBase64_Decode)

# 2. API Create method

At the Robot Answer, [Reply Type] - [Service Interface Call] - [Custom Interface] - [Create Custom Interface] fill in the interface name, URL, and add input and output parameters. 自定义接口 创建自定义接口 Input parameters, "parameters" are the parameters passed to the API The "name" is used to indicate the meaning of the parameter, "required" checks whether the parameter has a value when the interface is invoked, and "input suggestion" gives suggestions in the interface debug interface. In the output parameter, the parameter is API The name of the parameter returned. "Name" is used to indicate the meaning of this parameter. In the return state, the "status code" should be the same as the API Able to return. err_code A one-to-one correspondence, and the "name" indicates the meaning of the status code. When you click Save, you can see the newly created API, and can be modified, delete operations. In the header of the drop-down options to the right of the service interface call, you can see the API。

# 3. API Methods of Use

for API Requires a semantic slot for each input parameter of the. The contents of the semantic slot are called as the value of the parameter API, so you need to build a semantic slot in the semantic slot settings section, and set the way to fill the slot. for API The system will automatically create a semantic slot with the same name and set its dictionary to Sys. Interface backfill, can be used in the answer to show the return information. In the drop-down options to the right of the service interface call, select the API, click on the right side of the interface configuration to configure. In the parameter configuration tab, for each input parameter, its corresponding semantic slot must be selected (the optional list is the semantic slot already configured for that intent), And can set the default value to fill in when no value is provided, you can set the required parameters to ask the question (otherwise the default question will be used)For each output parameter, you must provide its corresponding semantic slot name, which will be created automatically. Interface debug tab, you can set the value of each parameter, click the debug button below, will be from OpenAI The backend tries to call the interface and shows the returned JSON Response. In addition, below the service interface call, you will see the label for each status code, OpenAI When the corresponding status code is obtained, it will jump to the response label for subsequent operations, including reply results, service interface calls, semantic slot information questioning, robot questioning, etc. The semantic slots that have been filled with the returned information are also available in subsequent steps. The same semantic slots can be overwritten and filled in subsequent steps.

# 4. Sample configuration

API配置 接口配置 回复配置