Skip to content

Commit 69f6239

Browse files
threadByExternalId support (#95)
1 parent 79660d4 commit 69f6239

File tree

4 files changed

+63
-25
lines changed

4 files changed

+63
-25
lines changed

.changeset/rotten-crabs-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@team-plain/typescript-sdk': patch
3+
---
4+
5+
Adds the ability to get a thread by its external id

src/client.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
ReplyToThreadDocument,
4343
SendNewEmailDocument,
4444
SnoozeThreadDocument,
45+
ThreadByExternalIdDocument,
4546
ThreadDocument,
4647
type ThreadEventPartsFragment,
4748
type ThreadPartsFragment,
@@ -445,6 +446,21 @@ export class PlainClient {
445446
return unwrapData(res, (q) => q.thread);
446447
}
447448

449+
/**
450+
* Get a single thread by external id. A thread's external id is unique per customer,
451+
* hence why the customer id is also required.
452+
*/
453+
async getThreadByExternalId(
454+
variables: VariablesOf<typeof ThreadByExternalIdDocument>
455+
): SDKResult<ThreadPartsFragment | null> {
456+
const res = await request(this.#ctx, {
457+
query: ThreadByExternalIdDocument,
458+
variables,
459+
});
460+
461+
return unwrapData(res, (q) => q.threadByExternalId);
462+
}
463+
448464
/**
449465
* Create a thread (e.g. when a contact form is submitted)
450466
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query threadByExternalId($customerId: ID!, $externalId: ID!) {
2+
threadByExternalId(customerId: $customerId, externalId: $externalId) {
3+
...ThreadParts
4+
}
5+
}

0 commit comments

Comments
 (0)