diff --git a/src/cruds/stream_messages.ts b/src/cruds/stream_messages.ts new file mode 100644 index 0000000..82fbffb --- /dev/null +++ b/src/cruds/stream_messages.ts @@ -0,0 +1,44 @@ +import { ApolloClient } from "apollo-client"; +import gql from "graphql-tag"; + +export class STREAM_MESSAGES { + public fetching: boolean; + private _client: ApolloClient; + private _socket; + + constructor(client, socket) { + this._client = client; + this._socket = socket; + } + + send(agentId: number, body: string, metadata: any = {}): Promise { + const QUERY_FUNTCION = "sendAgentStreamMessage"; + + const MUTATION = gql` + mutation ${QUERY_FUNTCION}($postMessage: SendAgentStreamMessageInput!) { + ${QUERY_FUNTCION}(input: $postMessage) { + clientMutationId + success + } + } + `; + + const postMessage = { + clientMutationId: "not_used", + agentId, + body, + metadata, + }; + + return this._client + .mutate({ + mutation: MUTATION, + variables: { postMessage }, + }) + .then((response) => response.data[QUERY_FUNTCION]) + .catch((e) => { + console.log(e); + return e; + }); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2708838..e236350 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import fetch from "node-fetch"; import { SYSTEMLOGS } from "./cruds/system_logs"; import { USERACCOUNT } from "./cruds/userAccounts"; import { MAPOBJECTS } from "./cruds/map_objects"; +import { STREAM_MESSAGES } from "./cruds/stream_messages"; import { INSTANT_ACTIONS } from "./cruds/instant_actions"; import { MISSIONQUEUE } from "./cruds/mission_queue"; import { AGENTS_INTERCONNECTIONS } from "./cruds/tools_interconnections"; @@ -53,6 +54,7 @@ export class HelyosServices { mapObjects: MAPOBJECTS; agents: AGENTS; yard: YARD; + streamMessages: STREAM_MESSAGES; instantActions: INSTANT_ACTIONS; systemLogs: SYSTEMLOGS; assignments: ASSIGNMENT; @@ -116,6 +118,7 @@ export class HelyosServices { if (this.connected) { this.mapObjects = new MAPOBJECTS(this._client, this.socket); this.userAccounts = new USERACCOUNT(this._client, this.socket); + this.streamMessages = new STREAM_MESSAGES(this._client, this.socket); this.instantActions = new INSTANT_ACTIONS(this._client, this.socket); this.agents = new AGENTS(this._client, this.socket); this.missionQueue = new MISSIONQUEUE(this._client, this.socket);