@reititin/client 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import http2 from 'http2';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
|
|
4
|
-
const FINALIZE_URL = "https://
|
|
4
|
+
const FINALIZE_URL = "https://reititin.com/api/finalizeMessage";
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const ReititinClient = ({ agentId, onMessage }) => {
|
|
7
7
|
const MESSAGE_ENDPOINT = `/api/agents/messages?agentId=${agentId}`;
|
|
8
8
|
let buffer = "";
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ export const createApukoneClient = ({ agentId, onMessage }) => {
|
|
|
11
11
|
if (buffer) return;
|
|
12
12
|
console.log("Waiting for messages.");
|
|
13
13
|
|
|
14
|
-
const client = http2.connect('https://
|
|
14
|
+
const client = http2.connect('https://reititin.com');
|
|
15
15
|
const req = client.request({ ':method': 'GET', ':path': MESSAGE_ENDPOINT, 'accept': 'text/event-stream' })
|
|
16
16
|
.setEncoding('utf8');
|
|
17
17
|
|
|
@@ -24,7 +24,7 @@ export const createApukoneClient = ({ agentId, onMessage }) => {
|
|
|
24
24
|
const agent_id = lines.find(line => line.startsWith('agent_id:'))?.split(': ')[1];
|
|
25
25
|
const rawData = lines.find(line => line.startsWith('data:'))?.replace('data: ', '');
|
|
26
26
|
if (onMessage) {
|
|
27
|
-
const processedMessage = await onMessage(rawData);
|
|
27
|
+
const processedMessage = await onMessage(JSON.parse(rawData));
|
|
28
28
|
await axios.post(FINALIZE_URL, { chat_id: chat_id, agent_id: agent_id, message: processedMessage });
|
|
29
29
|
console.log(`Response sent.`);
|
|
30
30
|
}
|