Sleamhnú go príomh-ábhar

Tosaigh Tapa Gréasáin Real-Time Websocket

Tugann an tosaigh tapa seo le chéile an íosmhéid a theastaíonn uait chun tosú ag fáil imeachtaí fíor-ama Legalesign GraphQL.

eolas

Má roghnaíonn tú glaonna freagra freastalaí-go-freastalaí seachas ceangail sheasmhacha, tá webhooks ar fáil freisin (mínítear sa chuid REST API).

Ag baint úsáide as cúnamhchódaithe AI?

Chun na torthaí is fearr a fháil, tabhair na leathanaigh seo le chéile do do uirlis AI:

Déanfaidh tú:

  • token rochtana a fháil
  • ceangal websocket AppSync a oscailt
  • sliús úsáideora nó grúpa a shíntiús
  • lipéad imeachta a pharsáil
  • rianú ar category agus event

Roimh duit Tosú

Teastaíonn uait:

  • rochtain API a bheith cumasaithe do do chuntas
  • cuntas úsáideora Legalesign
  • token rochtana
  • groupId má tá tú ag iarraidh subscribeGroupFeed a úsáid

Tosaigh anseo má tá na céimeanna sin fós le déanamh agat:

Céim 1: Roghnaigh Sliús

Úsáid:

  • subscribeUserFeed do imeachtaí dírithe ar úsáideoir cosúil le dul chun cinn uaslódála
  • subscribeGroupFeed do imeachtaí dírithe ar ghrúpa cosúil le nuashonruithe doiciméad, faighteoirí, teimpléid, tascanna, creidmheasanna, agus saolré

Sliús úsáideora

subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}

Sliús grúpa

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

Céim 2: Ceangail leis an bPointe deiridh Websocket

Úsáid an pointe deiridh websocket AppSync:

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

Pas do thóicín béalaithe isteach sna paraiméadair nascála.

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}`,
},
});

Céim 3: Síntiús

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'),
}
);

Céim 4: Páirsiú an Paileáda Fholamh

Filltear an réimse suibscríobha ar:

  • mála seachadta (groupIduserId)
  • sreang JSON i data

Páirsigh an réimse data inmheánach sula ndéanann tú aon ní eile:

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

Sampla:

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);
}