如何在NodeJS中发布GraphQL突变?

时间:2019-06-21 19:30:48

标签: node.js https graphql dialogflow

我指的是https://develop.zendesk.com/hc/en-us/articles/360001331787 开始座席会话中给出的过程。我已经生成了访问令牌。现在,当我尝试执行POST请求时,收到的响应是 Bad Request 错误。

我正在使用Cloud function Billed环境执行代码,我尝试使用JSON.stringify,也尝试将变异作为主体直接发送。但是没有任何效果。我得到的只是错误请求错误。

*** Error in `./names.exe': double free or corruption (top): 0x00000000011d3010 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x81499)[0x7f702b1bc499]
/lib64/libc.so.6(closedir+0xd)[0x7f702b1fbaed]
./names.exe[0x40068d]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f702b15d445]
./names.exe[0x400579]
======= Memory map: ========

预期结果应该类似于

'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const https = require("https");
process.env.DEBUG = 'dialogflow:debug';

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });

function welcome(agent) {  agent.add('My external DF Welcome agent!'); }

function getData(agent){
      const query = `mutation {  startAgentSession(access_token: "MyToken") { websocket_url session_id client_id}}`;
      console.log(JSON.stringify(query));
      const options = {
      hostname:'chat-api.zopim.com',
      path:'/graphql/request',
      method:'POST',
      query: query,
      headers: {'Content-Type':  'application/json'}
    };
      console.log(options);

      const req = https.request(options, (res) => {
              console.log('statusCode:', res.statusCode);
              console.log('headers:', res.headers);  
              res.on('data', (d) => {console.log('Data from res is>>>>', d.toString('utf8'));
                     agent.add(`Received data`);
                                    });   
         });

          req.on('error', (e) => {console.log("Error encountered>>>>.", e);  });
          req.end();
    }
  let intentMap = new Map(); 
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('getcode', getData);
  agent.handleRequest(intentMap);
  });

以下是const选项的正文,以了解输入内容:

{
  "data": {
    "startAgentSession": {
      "websocket_url":"wss://chat-api.zopim.com/stream/0.1/graphql/8b40lm:9012841289",
      "session_id":"MysessionID",
      "client_id":"MYClientID"
    }
  }
}

日志输出在这里:

 textPayload:  "{ hostname: 'chat-api.zopim.com',
  path: '/graphql/request',
  method: 'POST',
  query: 'mutation {  startAgentSession(access_token: "My_Token") { websocket_url session_id client_id}}',
  headers: { 'Content-Type': 'application/json' } }"  
 timestamp:  "2019-06-24T10:36:40.344Z"  

0 个答案:

没有答案