您只需发出http请求:
var http = require('https')
var options = {
host: 'konnectprodstream3.knowlarity.com',
port: 8200,
path: '/update-stream/02a53c9aec84/konnect',
method: 'GET'
}
const req = http.request(options, (response) => {
response.on('data', function (chunk) {
console.log({ chunk: chunk.toString() })
})
response.on('end', function () {
console.log('End')
})
})
req.end()
它将打印:
{chunk:'id:20\n'+'数据:{“event_type”:“customer_answer”,“business_call_type”:“出站”,“agent_number”:“+919911782019”,“call_recording”:NULL,“knowlarity_number”:“+919311583261”,“uuid”:“10e5bf5d-8e9f-465d-8920-3d0995210aae”,“call_direction”:“出站”,“caller”:“+919899625014”,“customer_number”:“
因为服务器已发送事件的格式为:
id: 20\n
data: <json>\n
\n # end of the message
您需要编写一个解析器