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.
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).
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
categoryagusevent
Mus tòisich thu
Feumaidh tu:
- ruigsinneachd API air a ghnìomhachadh airson do chunntas
- cunntas-cleachdaidh Legalesign
- token ruigsinneachd
groupIdma tha thu airsonsubscribeGroupFeeda chleachdadh
Tòisich an-seo ma cha do rinn thu na ceumannan sin fhathast:
Ceum 1: Tagh Biadhadh
Cleachd:
subscribeUserFeedairson tachartasan stèidhichte air neach-cleachdaidh leithid adhartas luchdachaidhsubscribeGroupFeedairson 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 (
groupIdnouserId) - 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:
categoryairson teagmhachadh air teaghlach an tachartaiseventairson 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:
- eadar-aghaidh cleachdaidh giullachd faidhle: Cum sùil air adhartas luchdachaidh le Fo-sgrìobhaidhean
- eadar-aghaidh cleachdaidh sruth-obrach seòladh: Cum sùil air dreuchdan cur air adhart le Fo-sgrìobhaidhean
- eadar-aghaidh cleachdaidh clàr obrach/gnìomhachd: Cum sùil air beatha-beatha sgrìobhainn agus faighinn le Fo-sgrìobhaidhean