Leum gu prìomh susbaint

Tòiseachadh Luath Websocket Fìor-ùine

Tha an tòiseachadh luath seo a’ cruinneachadh as ìsle a dh’ fheumas tu airson tòiseachadh air tachartasan Legalesign GraphQL fìor-ùine fhaighinn.

fiosrachadh

Ma bhios tu a’ roghnachadh freagairtean frithealaiche-ri-frithealaiche an àite ceanglaichean seasmhach, tha webhooks rim faighinn cuideachd (air an tuigsinn sa earrainn REST API).

A’ cleachdadh neach-taic còdaidh AI?

Gus na toraidhean as fheàrr fhaighinn, thoir na duilleagan seo don inneal AI agad còmhla:

Nì thu:

  • faigh token ruigsinneachd
  • fosgail ceangal websocket AppSync
  • fo-sgrìobh gu biadhadh neach-cleachdaidh no buidheann
  • mìneachadh air oighreachd an tachartais
  • rian air category agus event

Mus tòisich thu

Feumaidh tu:

  • ruigsinneachd API air a ghnìomhachadh airson do chunntas
  • cunntas-cleachdaidh Legalesign
  • token ruigsinneachd
  • groupId ma tha thu airson subscribeGroupFeed a chleachdadh

Tòisich an-seo ma cha do rinn thu na ceumannan sin fhathast:

Ceum 1: Tagh Biadhadh

Cleachd:

  • subscribeUserFeed airson tachartasan stèidhichte air neach-cleachdaidh leithid adhartas luchdachaidh
  • subscribeGroupFeed airson tachartasan stèidhichte air buidheann leithid ùrachaidhean sgrìobhainn, faighinn, teamplaid, dreuchd, creideas, agus beatha-beatha

Biadhadh neach-cleachdaidh

subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}

Biadhadh buidheann

subscription SubscribeGroupFeed($groupId: String!) {
subscribeGroupFeed(groupId: $groupId) {
groupId
data
}
}

Ceum 2: Ceangail ris an Fhrithealaiche Websocket

Cleachd crìoch-lìn websocket AppSync:

wss://graphql.uk.legalesign.com/graphql

Thoir seachad do token bearer anns na paramadairean ceangail.

import { createClient } from 'graphql-ws';
import WebSocket from 'ws';

const client = createClient({
url: 'wss://graphql.uk.legalesign.com/graphql',
webSocketImpl: WebSocket,
connectionParams: {
Authorization: `Bearer ${accessToken}`,
},
});

Ceum 3: Fo-sgrìobh

client.subscribe(
{
query: `
subscription SubscribeGroupFeed($groupId: String!) {
subscribeGroupFeed(groupId: $groupId) {
groupId
data
}
}
`,
variables: {
groupId: '<your-group-id>',
},
},
{
next: ({ data }) => {
console.log('raw message', data);
},
error: console.error,
complete: () => console.log('subscription closed'),
}
);

Ceum 4: Mìneachadh air a’ Phàigheadh a-staigh

Tha an raon fo-sgrìobhaidh a’ tilleadh:

  • bogsa lìbhrigidh (groupId no userId)
  • sreang JSON anns an data

Dèan mìneachadh air a’ raon data a-staigh mus dèan thu gin eile:

const parseEnvelope = (payload) => {
const raw = payload?.data;
if (!raw) return null;
return typeof raw === 'string' ? JSON.parse(raw) : raw;
};

Eisimpleir:

next: ({ data }) => {
const wrapper = data?.subscribeGroupFeed;
const event = parseEnvelope(wrapper);

console.log('event id', event?.eventId);
console.log('category', event?.category);
console.log('event', event?.event);
console.log('payload', event?.data);
}

Ceum 5: Rèiteach air category agus event

Na cruthaich amalachadh ùra mun cuairt còdan seann-fhasanta systemMessage-stoidhle.

Cleachd:

  • category airson teagmhachadh air teaghlach an tachartais
  • event airson comharrachadh air a’ cheum-sholais sònraichte

Eisimpleirean:

  • category: "upload", event: "uploadCompleted"
  • category: "task", event: "taskCompleted"
  • category: "documentLifecycle", event: "documentCreated"
  • category: "recipientLifecycle", event: "recipientVisiting"

Modalan tòiseachaidh àbhaisteach

Ma tha thu a’ taghadh càite an tòisicheadh: