Dialogflow日志在堆栈驱动程序中给了我一个不带逗号的JSON

时间:2019-06-10 00:19:11

标签: dialogflow stackdriver

我正在使用dialogflow创建聊天机器人,在将bigquery链接到datastudio以向客户端显示数据面板之后,我想恢复所有消息并将其发送到bigquery。

Dialogflow会将所有日志准确地发送到stackdriver,但是当textPayload打开时,它没有逗号将其用作通用JSON。

有什么想法吗?

Stackdriver log

Dialogflow Response : id: "3f6c4006-e8fd-4c59-af75-1f62e5785c3c-2dd8e723"
lang: "es"
session_id: "d1eea2ea-3dcc-447c-8883-a23a89d9e570"
timestamp: "2019-06-09T20:21:24.465Z"
result {
  source: "agent"
  resolved_query: "Comunidad"
  score: 1.0
  parameters {
  }
  contexts {
    name: "generic"
    lifespan: 4
    parameters {
      fields {
        key: "facebook_sender_id"
        value {
          string_value: "2665762213453771"
        }
      }
    }
  }
  metadata {
    intent_id: "843d151c-ffaa-43a5-b1af-7537947aeb98"
    intent_name: "CommunityIntent"
    webhook_used: "false"
    webhook_for_slot_filling_used: "false"
    is_fallback_intent: "false"
  }
  fulfillment {
    speech: "Nuestra comunidad busca vincular desarrolladores para crecer como un ecosistema tecnol\303\263gico. Puedes checar m\303\241s sobre nuestros eventos en http://cloudmex.io/servicios/workshops-y-meetups/"
    messages {
      lang: "es"
      type {
        number_value: 0.0
      }
      speech {
        string_value: "Nuestra comunidad busca vincular desarrolladores para crecer como un ecosistema tecnol\303\263gico. Puedes checar m\303\241s sobre nuestros eventos en http://cloudmex.io/servicios/workshops-y-meetups/"
      }
    }
  }
}
status {
  code: 200
  error_type: "success"
}

**更新:堆栈驱动程序日志**

{
insertId:  "qd0nynfxfz53o"  
 labels: {
  protocol:  "V2"   
  request_id:  "7034b4ec-3b54-4f0c-9cee-8a37eb117f66-2dd8e723"   
  source:  "facebook"   
  type:  "dialogflow_response"   
 }
 logName:  "projects/cloudy-76f21/logs/dialogflow_agent"  
 receiveTimestamp:  "2019-06-09T19:32:53.416394429Z"  
 resource: {
  labels: {
   project_id:  "cloudy-76f21"    
  }
  type:  "global"   
 }
 severity:  "INFO"  
 textPayload:  "Dialogflow Response : id: "7034b4ec-3b54-4f0c-9cee-8a37eb117f66-2dd8e723"
lang: "es"
session_id: "d1eea2ea-3dcc-447c-8883-a23a89d9e570"
timestamp: "2019-06-09T19:32:53.334Z"
result {
  source: "agent"
  resolved_query: "Prueba"
  action: "input.unknown"
  score: 1.0
  parameters {
  }
  contexts {
    name: "generic"
    lifespan: 4
    parameters {
      fields {
        key: "facebook_sender_id"
        value {
          string_value: "2665762213453771"
        }
      }
    }
  }
  metadata {
    intent_id: "25d76718-8282-47ae-999e-55c40baba860"
    intent_name: "Default Fallback Intent"
    webhook_used: "false"
    webhook_for_slot_filling_used: "false"
    is_fallback_intent: "true"
  }
  fulfillment {
    speech: "Si es necesario puedes pedirme ayuda con solo mencionarlo."
    messages {
      lang: "es"
      type {
        number_value: 0.0
      }
      speech {
        string_value: "Si es necesario puedes pedirme ayuda con solo mencionarlo."
      }
    }
  }
}
status {
  code: 200
  error_type: "success"
}
"  
 timestamp:  "2019-06-09T19:32:53.416394429Z"  
 trace:  "d1eea2ea-3dcc-447c-8883-a23a89d9e570"  
}

1 个答案:

答案 0 :(得分:0)

当应用程序将日志写入Stackdriver时,它可以写入一行文本或结构化有效负载。取决于编写应用程序的选择内容。看来Dialog流程正在编写以下形式的文本行:

Dialogflow Request : <Rest of text>

其中<Rest of text>似乎是JSON字符串。如果是这种情况,可以说Dialogflow在使用Stackdriver编写时不会表现得很好,但是可能会有我们不熟悉的故事。无论哪种方式,我们都拥有。

我们现在需要做的是考虑将这些数据转换为可以使用的形式。如果我们假设您只需要Dialogflow请求的JSON表示,那么我们要做的就是从Stackdriver中检索记录并找到textPayload行。如果它们以Dialogflow Request :开头,那么我们将其剥离下来,以解析其余部分作为JSON,我们就有了数据。

执行此操作的方法有很多,选择取决于您要如何处理数据。假设您不需要实时实时解析,那么我会将Stackdriver日志导出为GCS对象(文件),并通过诸如Datafusion(或您自己的手写解析器)之类的ETL工具传递它们。然后,可以将生成的数据写入新的GCS文件中,然后导入到BigQuery中。

如果需要实时处理,尽管其中之一是将Stackdriver日志消息写入PubSub,并让Cloud Function在写入时获取每条记录。该函数可以解析我们的数据并将其写入BigQuery。

相关问题