Dialogflow实现与Azure函数REST响应不兼容

时间:2019-03-06 10:15:08

标签: java azure-functions dialogflow dialogflow-fulfillment azure-zulu

我正在尝试使用Azure Java函数从Dialogflow获得充实响应,每当Dialogflow rest客户端调用Azure函数时,它都会引发错误-

Webhook呼叫失败。错误:无法解析webhook JSON响应:预期消息对象,但得到:“─㜀䈀─㈀㈀昀甀氀昀碗氀氀洀攀渀琀吀攀砀琀─㈀㈀─㌀䄀⬀渀甀氀氀─㈀䌀─㈀㈀昀甀氀昀碗氀氀洀攀渀琀䴀攀猀猀愀最攀猀─㈀㈀─㌀䄀⬀─㔀䈀─㔀䐀─㈀䌀─㈀㈀猀漀甀爀挀─㈀攀─㈀ ㈀─㌀䄀⬀渀甀氀氀─㈀䌀─㈀㈀瀀愀礀氀漀愀搀─㈀㈀─㈀㈀─㌀䄀⬀─㜀䈀─㈀㈀最漀漀最氀攀─㈀㈀─㌀䄀⬀─㜀䈀─㈀㈀攀砀瀀攀挀琀唀猀攀挀琀唀猀攀爀刀攀猀瀀漀渀猀攀─㈀㈀─㌀䄀⬀昀愀氀猀攀─㈀䌀─㈀㈀甀猀攀爀匀

我能够找到一些链接来获取解决方案,但没有任何帮助,这些是我找到的链接-

  1. Webhook call failed. Error: Failed to parse webhook JSON response: Expect message object but got: [Chinese letters]
  2. https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/197
  3. https://productforums.google.com/forum/#!msg/dialogflow/QVmOFwXXuOU/CAEv1MgQAgAJ;context-place=forum/dialogflow
  4. Azure function sends chunked response and Dialogflow does not process it
  5. https://github.com/googleapis/google-cloud-dotnet/issues/2258
  6. Dialogflow Webhook Response c# gives error on invoke

在最后两个链接中,在dotnet中有一个解决方案,而在Java中没有。

我也尝试返回String和Json Object,但没有任何结果。

下面是我使用的Azure函数Java代码-

 @FunctionName("TriggerStringPost")
    public HttpResponseMessage run(
            @HttpTrigger(name = "req", 
              methods = {HttpMethod.POST}, 
              authLevel = AuthorizationLevel.ANONYMOUS)
            HttpRequestMessage<Optional<String>> request,
            final ExecutionContext context) {

    // Check request body
    if (!request.getBody().isPresent()) {
        return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
                      .body("Document not found.")
                      .build();
    } 
    else {
        // return JSON from to the client
        // Generate document
        final String body = request.getBody().get();
        final String jsonDocument = "{\"id\":\"123456\", " + 
                                     "\"description\": \"" + body + "\"}";
        return request.createResponseBuilder(HttpStatus.OK)
                      .header("Content-Type", "application/json")
                      .body(jsonDocument)
                      .build();
    }
}

谢谢,请帮助我找到解决方案。

0 个答案:

没有答案