@awesomate/sdk 0.90.0 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +260 -1
- package/dist/index.js +99 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* Docs: https://hub.awesomate.ai/docs/sdk/
|
|
27
27
|
*/
|
|
28
28
|
/** This package's version, sent to the hub with every server call. */
|
|
29
|
-
export declare const VERSION = "0.
|
|
29
|
+
export declare const VERSION = "0.93.0";
|
|
30
30
|
/** Augmented by the generated awesomate.d.ts, so each kind's rows are typed. */
|
|
31
31
|
export interface Kinds {
|
|
32
32
|
}
|
|
@@ -1385,6 +1385,30 @@ export declare class AwesomateClient {
|
|
|
1385
1385
|
}) => Promise<EmailBrief>;
|
|
1386
1386
|
/** The result of a `brief()` that answered `pending`: still `pending`, or the questions or the draft. */
|
|
1387
1387
|
briefStatus: (jobId: string) => Promise<EmailBrief>;
|
|
1388
|
+
/**
|
|
1389
|
+
* The addresses an email can go from (needs `own_address` on the account): the sending name, then
|
|
1390
|
+
* each of the account's own ready addresses with its uses and whether it fits an email to a list,
|
|
1391
|
+
* or to `picked` people picked by hand (50 or fewer is one-to-one). Null when there are no own
|
|
1392
|
+
* addresses: every email goes from the sending name. Pass a choice's `value` as `from` on `draft()`.
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
* const choices = await db.emails.fromChoices({ picked: 1 });
|
|
1396
|
+
* const own = choices?.find((c) => c.own && c.allowed);
|
|
1397
|
+
*/
|
|
1398
|
+
fromChoices: (opts?: {
|
|
1399
|
+
picked?: number;
|
|
1400
|
+
}) => Promise<EmailFromChoice[] | null>;
|
|
1401
|
+
/**
|
|
1402
|
+
* The usual From for each kind of email (`one_to_one`: an email to one person; `automation`: an
|
|
1403
|
+
* automation's service email that names no From), and the owner's own addresses it can be. Needs crm:read.
|
|
1404
|
+
*/
|
|
1405
|
+
fromDefaults: () => Promise<EmailFromDefaults>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Set the usual From for a kind of email to one of the owner's own ready addresses set up for it,
|
|
1408
|
+
* or `'sending_name'` to go back to the sending name. Only the account owner's key (needs crm:draft
|
|
1409
|
+
* and `own_address`). It never adds or proves an address: the owner does that in the hub.
|
|
1410
|
+
*/
|
|
1411
|
+
setFromDefault: (kind: EmailFromDefaultKind, from: string) => Promise<EmailFromDefaults>;
|
|
1388
1412
|
};
|
|
1389
1413
|
/**
|
|
1390
1414
|
* Email series: emails that go to one person at a time over days, starting when something
|
|
@@ -1728,6 +1752,18 @@ export declare class AwesomateClient {
|
|
|
1728
1752
|
get: (id: string, options?: {
|
|
1729
1753
|
tz?: string;
|
|
1730
1754
|
}) => Promise<ContactDetail | null>;
|
|
1755
|
+
/**
|
|
1756
|
+
* New leads waiting on whoever this token belongs to (the owner's token sees every one), newest
|
|
1757
|
+
* first, at most 50: open ones, and ones marked answered in the last 14 days. Each has the
|
|
1758
|
+
* person's id (`contactId`), their name where your token may read it (null otherwise), how they
|
|
1759
|
+
* came in (`door`, and `doorWords` such as 'your form') and how long it waited. To answer one,
|
|
1760
|
+
* draft a one-to-one service email to them (emails.draft with people and no list), which the
|
|
1761
|
+
* owner sends from the hub. Needs crm:read and New leads on the account (`lead_alert`).
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* const waiting = (await db.contacts.leads()).filter((l) => !l.answered);
|
|
1765
|
+
*/
|
|
1766
|
+
leads: () => Promise<Lead[]>;
|
|
1731
1767
|
/**
|
|
1732
1768
|
* The person with exactly this email is changed, or added when there is none. `created: false`
|
|
1733
1769
|
* means someone already had the address, and what you sent replaced their values. Tags are
|
|
@@ -2041,6 +2077,34 @@ export declare class AwesomateClient {
|
|
|
2041
2077
|
* await db.archiveLink('vehicle', 'serviced_at');
|
|
2042
2078
|
*/
|
|
2043
2079
|
archiveLink(kind: string, key: string): Promise<KindDescription>;
|
|
2080
|
+
/**
|
|
2081
|
+
* Contacts settings. `leadAlert()` reads the New leads setting: whether a new lead gives someone a
|
|
2082
|
+
* task, and who answers them. `setLeadAlert()` changes it, on the account owner's own token only
|
|
2083
|
+
* (anyone else's throws `forbidden`, server code `finish_in_hub`, and the owner changes it in the
|
|
2084
|
+
* hub at `settingsUrl`). Needs New leads on the account (`lead_alert`).
|
|
2085
|
+
*
|
|
2086
|
+
* @example
|
|
2087
|
+
* const alert = await db.setup.leadAlert();
|
|
2088
|
+
* if (alert.canChange) await db.setup.setLeadAlert({ answeredBy: 'owner' });
|
|
2089
|
+
*/
|
|
2090
|
+
readonly setup: {
|
|
2091
|
+
/** The New leads setting. crm:read; any token may read it. */
|
|
2092
|
+
leadAlert: () => Promise<LeadAlertSetting>;
|
|
2093
|
+
/**
|
|
2094
|
+
* Change the New leads setting: `on`, and `answeredBy` ('map': the role the business map puts
|
|
2095
|
+
* in Enquiries and quotes, else the owner; 'owner'; or `{ roleId }` from the business map).
|
|
2096
|
+
* crm:write, the account owner's own token only. Answers the setting as it is now, with
|
|
2097
|
+
* `changed` false when it already was.
|
|
2098
|
+
*/
|
|
2099
|
+
setLeadAlert: (change: {
|
|
2100
|
+
on?: boolean;
|
|
2101
|
+
answeredBy?: "map" | "owner" | {
|
|
2102
|
+
roleId: number;
|
|
2103
|
+
};
|
|
2104
|
+
}) => Promise<LeadAlertSetting & {
|
|
2105
|
+
changed: boolean;
|
|
2106
|
+
}>;
|
|
2107
|
+
};
|
|
2044
2108
|
/**
|
|
2045
2109
|
* Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
|
|
2046
2110
|
* ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
|
|
@@ -2222,6 +2286,24 @@ export declare class AwesomateClient {
|
|
|
2222
2286
|
businessJourneyQueue(step: number, opts?: {
|
|
2223
2287
|
page?: number;
|
|
2224
2288
|
}): Promise<BusinessJourneyQueue>;
|
|
2289
|
+
/**
|
|
2290
|
+
* The business's agents in one read: every helper on the map (agents, n8n agents, automations) with
|
|
2291
|
+
* its role, level and who looks after it, what it did in the last 7 or 30 days (conversations, ones
|
|
2292
|
+
* it could not answer or passed to a person, tasks raised, decisions filed, runs and errors), what is
|
|
2293
|
+
* waiting on a person because of it, and its role's KPIs with what feeds each figure. Counts, times
|
|
2294
|
+
* and ids only, never a conversation's or task's words. A figure a kind of helper does not have is
|
|
2295
|
+
* null, never 0. hosting:read and the agentic business feature (`feature_unavailable` otherwise). The
|
|
2296
|
+
* owner's own key reads every helper (`scope` `'all'`); a person's own key reads the helpers on roles
|
|
2297
|
+
* whose KPIs they would see (`'yours'`); a narrow key reads none.
|
|
2298
|
+
*
|
|
2299
|
+
* ```ts
|
|
2300
|
+
* const { rows } = await db.businessAgents({ period: 30 });
|
|
2301
|
+
* for (const a of rows.filter((x) => x.needsPerson.count > 0)) console.log(a.label, a.needsPerson.count);
|
|
2302
|
+
* ```
|
|
2303
|
+
*/
|
|
2304
|
+
businessAgents(opts?: {
|
|
2305
|
+
period?: 7 | 30;
|
|
2306
|
+
}): Promise<BusinessAgents>;
|
|
2225
2307
|
/**
|
|
2226
2308
|
* The business's KPIs: each a number with a target and someone responsible for it, with where it
|
|
2227
2309
|
* sits, who answers for it, its light against the target for the last complete period, the period
|
|
@@ -2792,6 +2874,94 @@ export interface BusinessJourneyQueueRecord {
|
|
|
2792
2874
|
/** The open task raised because it ran late, if any. */
|
|
2793
2875
|
roleTaskId: number | null;
|
|
2794
2876
|
}
|
|
2877
|
+
/** One KPI on an agent's role, with what feeds its figure. */
|
|
2878
|
+
export interface BusinessAgentKpi {
|
|
2879
|
+
slug: string;
|
|
2880
|
+
name: string;
|
|
2881
|
+
light: KpiLight;
|
|
2882
|
+
/** Say this beside any colour. */
|
|
2883
|
+
lightWord: string;
|
|
2884
|
+
/** What feeds its figure: a helper on the map (by id), else who writes it, in words. */
|
|
2885
|
+
contributors: Array<{
|
|
2886
|
+
helperId: number | null;
|
|
2887
|
+
label: string;
|
|
2888
|
+
writtenBy: 'automation' | 'person' | 'agent';
|
|
2889
|
+
}>;
|
|
2890
|
+
}
|
|
2891
|
+
/** One helper on the map, as businessAgents() returns it. Every count is over the period; null where the helper has no such thing (an automation has no conversations). An automation's `runs`, `errors` and `lastRunAt` are also null when its runs could not be read or it has no workflow yet: never read that as no runs. */
|
|
2892
|
+
export interface BusinessAgent {
|
|
2893
|
+
/** The map helper's id. */
|
|
2894
|
+
id: number;
|
|
2895
|
+
/** 'agent' (an Awesomate agent), 'n8n_agent', 'build', 'template', 'bundle' or 'external'. */
|
|
2896
|
+
kind: string;
|
|
2897
|
+
ref: string;
|
|
2898
|
+
label: string;
|
|
2899
|
+
/** `department.no` is a fixed key, never said to people: say `department.name`. */
|
|
2900
|
+
role: {
|
|
2901
|
+
id: number;
|
|
2902
|
+
slug: string;
|
|
2903
|
+
title: string;
|
|
2904
|
+
department: {
|
|
2905
|
+
no: number;
|
|
2906
|
+
name: string;
|
|
2907
|
+
};
|
|
2908
|
+
};
|
|
2909
|
+
/** True when it holds the role, not only helps on it. */
|
|
2910
|
+
holds: boolean;
|
|
2911
|
+
/** `runsAt` is the level its runs start at; null when it holds its role with no level of its own (each process's level applies). */
|
|
2912
|
+
level: {
|
|
2913
|
+
declared: number | null;
|
|
2914
|
+
runsAt: number | null;
|
|
2915
|
+
};
|
|
2916
|
+
lookedAfterBy: string;
|
|
2917
|
+
/** An Awesomate agent on or off; null for anything else, or when that read was incomplete. */
|
|
2918
|
+
state: 'on' | 'off' | null;
|
|
2919
|
+
status: {
|
|
2920
|
+
conversations: number | null;
|
|
2921
|
+
couldntAnswer: number | null;
|
|
2922
|
+
transferred: number | null;
|
|
2923
|
+
tasksRaised: number | null;
|
|
2924
|
+
tasksOpen: number | null;
|
|
2925
|
+
decisionsFiled: number | null;
|
|
2926
|
+
decisionsWaiting: number | null;
|
|
2927
|
+
runs: number | null;
|
|
2928
|
+
errors: number | null;
|
|
2929
|
+
lastRunAt: string | null;
|
|
2930
|
+
};
|
|
2931
|
+
/** The newest conversation, task, decision or run in the period; null when none. */
|
|
2932
|
+
lastActive: string | null;
|
|
2933
|
+
/** Waiting on a person because of it: decisions not answered, tasks it raised still open, transfers that rang out. Ids are capped at 5 each; `count` is the whole. */
|
|
2934
|
+
needsPerson: {
|
|
2935
|
+
count: number;
|
|
2936
|
+
decisionIds: number[];
|
|
2937
|
+
taskIds: number[];
|
|
2938
|
+
conversationIds: string[];
|
|
2939
|
+
};
|
|
2940
|
+
/** Its role's KPIs; null where the hub does not keep this account's KPIs (they are in Reports: read them with `businessKpis()`), or, with `'kpis'` in `unavailable`, where they could not be read. */
|
|
2941
|
+
kpis: BusinessAgentKpi[] | null;
|
|
2942
|
+
}
|
|
2943
|
+
/** The business's agents, as businessAgents() returns them. */
|
|
2944
|
+
export interface BusinessAgents {
|
|
2945
|
+
/** Days. */
|
|
2946
|
+
period: 7 | 30;
|
|
2947
|
+
since: string;
|
|
2948
|
+
asOf: string;
|
|
2949
|
+
/** 'all': every helper; 'yours': the roles this key sees KPIs for (a person's own key). A narrow key reads none: 'yours' with no rows, which never means no agents work there. */
|
|
2950
|
+
scope: 'all' | 'yours';
|
|
2951
|
+
/** Every row this key may read, not only the ones returned. */
|
|
2952
|
+
total: number;
|
|
2953
|
+
/** True when there were more than the 50 rows returned. */
|
|
2954
|
+
truncated: boolean;
|
|
2955
|
+
rows: BusinessAgent[];
|
|
2956
|
+
/** Helpers the map could not place on a role (scope 'all' only). */
|
|
2957
|
+
unplaced: Array<{
|
|
2958
|
+
kind: string;
|
|
2959
|
+
ref: string;
|
|
2960
|
+
label: string;
|
|
2961
|
+
}>;
|
|
2962
|
+
/** Parts that could not be read just now (their figures are null, never 0). */
|
|
2963
|
+
unavailable: string[];
|
|
2964
|
+
}
|
|
2795
2965
|
/** A step's queue, as businessJourneyQueue() returns it. */
|
|
2796
2966
|
export interface BusinessJourneyQueue {
|
|
2797
2967
|
asOf: string;
|
|
@@ -4564,6 +4734,41 @@ export interface RelatedRows {
|
|
|
4564
4734
|
/** Pass to query() with where { <link>_id: id } and after, for more. */
|
|
4565
4735
|
next: string | null;
|
|
4566
4736
|
}
|
|
4737
|
+
/** How a lead came in. */
|
|
4738
|
+
export type LeadDoor = 'app' | 'form' | 'booking' | 'chat' | 'social' | 'phone' | 'email' | 'automation';
|
|
4739
|
+
/** A new lead, from contacts.leads(). */
|
|
4740
|
+
export interface Lead {
|
|
4741
|
+
/** The lead's task in the hub. */
|
|
4742
|
+
taskId: number;
|
|
4743
|
+
/** The person's contact id. */
|
|
4744
|
+
contactId: string;
|
|
4745
|
+
/** Their first and last name where your token may read them, else null (never their email). */
|
|
4746
|
+
name: string | null;
|
|
4747
|
+
door: LeadDoor;
|
|
4748
|
+
/** The door in words: 'your form', 'your app', 'your website chat'. */
|
|
4749
|
+
doorWords: string;
|
|
4750
|
+
/** When they came in, ISO 8601. */
|
|
4751
|
+
at: string;
|
|
4752
|
+
answered: boolean;
|
|
4753
|
+
/** When it was marked answered, ISO 8601, or null. */
|
|
4754
|
+
answeredAt: string | null;
|
|
4755
|
+
/** Open: minutes since they came in. Answered: minutes it waited before it was answered. */
|
|
4756
|
+
minutesWaiting: number;
|
|
4757
|
+
}
|
|
4758
|
+
/** The New leads setting, from setup.leadAlert(). */
|
|
4759
|
+
export interface LeadAlertSetting {
|
|
4760
|
+
/** Whether a new lead gives someone a task. */
|
|
4761
|
+
on: boolean;
|
|
4762
|
+
/** 'map': the role the business map puts in Enquiries and quotes, else the owner. */
|
|
4763
|
+
answeredBy: 'map' | 'owner' | {
|
|
4764
|
+
roleId: number;
|
|
4765
|
+
title: string;
|
|
4766
|
+
};
|
|
4767
|
+
/** Whether this token may change it (the account owner's own token). */
|
|
4768
|
+
canChange: boolean;
|
|
4769
|
+
/** The hub page where the owner changes it. */
|
|
4770
|
+
settingsUrl: string;
|
|
4771
|
+
}
|
|
4567
4772
|
/** How a person asked to stop getting email, for contacts.unsubscribe(). */
|
|
4568
4773
|
export type ContactStopHow = 'reply' | 'phone' | 'in_person' | 'in_writing' | 'other';
|
|
4569
4774
|
/** What contacts.unsubscribe() recorded. */
|
|
@@ -5202,6 +5407,52 @@ export interface EmailDraftInput {
|
|
|
5202
5407
|
* is saved.
|
|
5203
5408
|
*/
|
|
5204
5409
|
record?: string | null;
|
|
5410
|
+
/**
|
|
5411
|
+
* Which address it goes from (needs `own_address`): `'sending_name'`, or one of the account's own
|
|
5412
|
+
* ready addresses from `fromChoices()`. Left out, a new one-to-one email from the owner's key goes from
|
|
5413
|
+
* the account's usual one-to-one From, and anything else keeps the From it has. Approval refuses an
|
|
5414
|
+
* address not set up for the email.
|
|
5415
|
+
*/
|
|
5416
|
+
from?: string;
|
|
5417
|
+
}
|
|
5418
|
+
/** The kinds of email a usual From is set for. */
|
|
5419
|
+
export type EmailFromDefaultKind = 'one_to_one' | 'automation';
|
|
5420
|
+
/** One address an email can go from, from `emails.fromChoices()` (and `from_choices` on `get()` and `preview()`). */
|
|
5421
|
+
export interface EmailFromChoice {
|
|
5422
|
+
/** `'sending_name'`, or the own address itself: what to pass as `from`. */
|
|
5423
|
+
value: string;
|
|
5424
|
+
address: string;
|
|
5425
|
+
/** An address of the business's own, at its own domain (not its sending name). */
|
|
5426
|
+
own: boolean;
|
|
5427
|
+
/** Whether this email could go from it now. */
|
|
5428
|
+
allowed: boolean;
|
|
5429
|
+
/** When it can't: the use it isn't switched on for. */
|
|
5430
|
+
needs?: 'one_to_one' | 'invites' | 'lists';
|
|
5431
|
+
/** When it can't: list emails from it are stopped for now. */
|
|
5432
|
+
paused?: boolean;
|
|
5433
|
+
/** An own address's uses, as the owner switched them on. */
|
|
5434
|
+
uses?: Array<'one_to_one' | 'invites' | 'lists'>;
|
|
5435
|
+
/** The name on its From line; null for the personal name. */
|
|
5436
|
+
name?: string | null;
|
|
5437
|
+
label: string;
|
|
5438
|
+
/** Why it can't be chosen for this email, in a sentence. */
|
|
5439
|
+
note?: string;
|
|
5440
|
+
/** For an own address on an email to many people: what the owner should know first. */
|
|
5441
|
+
warning?: string;
|
|
5442
|
+
}
|
|
5443
|
+
/** From `emails.fromDefaults()` and `emails.setFromDefault()`. */
|
|
5444
|
+
export interface EmailFromDefaults {
|
|
5445
|
+
/** Each kind: the address (null: the sending name), and whether it is used now (false: it no longer fits, so the sending name goes). */
|
|
5446
|
+
defaults: Array<{
|
|
5447
|
+
kind: EmailFromDefaultKind;
|
|
5448
|
+
address: string | null;
|
|
5449
|
+
applies: boolean;
|
|
5450
|
+
}>;
|
|
5451
|
+
/** The owner's own ready addresses, each with its uses: what a usual From can be. */
|
|
5452
|
+
addresses: Array<{
|
|
5453
|
+
address: string;
|
|
5454
|
+
uses: Array<'one_to_one' | 'invites' | 'lists'>;
|
|
5455
|
+
}>;
|
|
5205
5456
|
}
|
|
5206
5457
|
/** Who a picked-people email reaches, as a model may see it. */
|
|
5207
5458
|
export interface EmailReach {
|
|
@@ -5278,6 +5529,10 @@ export interface EmailPreview {
|
|
|
5278
5529
|
checks: EmailSeriesChecks | null;
|
|
5279
5530
|
reviewUrl: string;
|
|
5280
5531
|
next: string;
|
|
5532
|
+
/** The addresses it could go from (only when the account has its own ready addresses). */
|
|
5533
|
+
from_choices?: EmailFromChoice[];
|
|
5534
|
+
/** True when the choices could not be read just now. */
|
|
5535
|
+
from_choices_unread?: true;
|
|
5281
5536
|
}
|
|
5282
5537
|
/** From `emails.test()`. */
|
|
5283
5538
|
export interface EmailTestSent {
|
|
@@ -5349,6 +5604,10 @@ export interface EmailDetail {
|
|
|
5349
5604
|
shape?: 'direct';
|
|
5350
5605
|
/** A one-to-one email's record (the id of the job, booking or quote it is about), or null. */
|
|
5351
5606
|
record?: string | null;
|
|
5607
|
+
/** The addresses it could go from (only when the account has its own ready addresses). */
|
|
5608
|
+
from_choices?: EmailFromChoice[];
|
|
5609
|
+
/** True when the choices could not be read just now. */
|
|
5610
|
+
from_choices_unread?: true;
|
|
5352
5611
|
}
|
|
5353
5612
|
/** `emails.discard()`: the draft is stopped and left out of the lists. */
|
|
5354
5613
|
export interface EmailDiscarded {
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* Docs: https://hub.awesomate.ai/docs/sdk/
|
|
27
27
|
*/
|
|
28
28
|
/** This package's version, sent to the hub with every server call. */
|
|
29
|
-
export const VERSION = '0.
|
|
29
|
+
export const VERSION = '0.93.0';
|
|
30
30
|
const DEFAULT_BASE = 'https://hub.awesomate.ai';
|
|
31
31
|
/** The one check for a platform `watch_url` (mirrored in the hub's awesomate-knowledge.ts and its MCP). */
|
|
32
32
|
const WATCH_URL = /^https:\/\/[^\s"'<>]+$/i;
|
|
@@ -241,6 +241,10 @@ function keyPath(method, path) {
|
|
|
241
241
|
function contactsNeedAccount() {
|
|
242
242
|
return new AwesomateError('forbidden', 'This needs the account\'s token (amt_pat_...). An app key made for contacts reads them with contacts.search() or query(\'contact\').', 0);
|
|
243
243
|
}
|
|
244
|
+
/** A db.setup call on an app key: the account's own settings, refused before anything is sent. */
|
|
245
|
+
function setupNeedsAccount() {
|
|
246
|
+
return new AwesomateError('forbidden', 'This needs the account\'s token (amt_pat_...).', 0);
|
|
247
|
+
}
|
|
244
248
|
/** A person's id, checked before it is sent: anything but a UUID names nobody. */
|
|
245
249
|
function contactIdOf(id) {
|
|
246
250
|
if (!RECORD_ID.test(String(id)))
|
|
@@ -1104,6 +1108,31 @@ export class AwesomateClient {
|
|
|
1104
1108
|
},
|
|
1105
1109
|
/** The result of a `brief()` that answered `pending`: still `pending`, or the questions or the draft. */
|
|
1106
1110
|
briefStatus: async (jobId) => briefFromWire(await this.request('GET', `/api/my-crm/v1/emails/brief/${encodeURIComponent(jobId)}`)),
|
|
1111
|
+
/**
|
|
1112
|
+
* The addresses an email can go from (needs `own_address` on the account): the sending name, then
|
|
1113
|
+
* each of the account's own ready addresses with its uses and whether it fits an email to a list,
|
|
1114
|
+
* or to `picked` people picked by hand (50 or fewer is one-to-one). Null when there are no own
|
|
1115
|
+
* addresses: every email goes from the sending name. Pass a choice's `value` as `from` on `draft()`.
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* const choices = await db.emails.fromChoices({ picked: 1 });
|
|
1119
|
+
* const own = choices?.find((c) => c.own && c.allowed);
|
|
1120
|
+
*/
|
|
1121
|
+
fromChoices: async (opts = {}) => {
|
|
1122
|
+
const q = opts.picked !== undefined ? `?people=${encodeURIComponent(String(opts.picked))}` : '';
|
|
1123
|
+
return (await this.request('GET', `/api/my-crm/v1/emails/from-choices${q}`)).from?.choices ?? null;
|
|
1124
|
+
},
|
|
1125
|
+
/**
|
|
1126
|
+
* The usual From for each kind of email (`one_to_one`: an email to one person; `automation`: an
|
|
1127
|
+
* automation's service email that names no From), and the owner's own addresses it can be. Needs crm:read.
|
|
1128
|
+
*/
|
|
1129
|
+
fromDefaults: async () => this.request('GET', '/api/my-crm/v1/emails/from-defaults'),
|
|
1130
|
+
/**
|
|
1131
|
+
* Set the usual From for a kind of email to one of the owner's own ready addresses set up for it,
|
|
1132
|
+
* or `'sending_name'` to go back to the sending name. Only the account owner's key (needs crm:draft
|
|
1133
|
+
* and `own_address`). It never adds or proves an address: the owner does that in the hub.
|
|
1134
|
+
*/
|
|
1135
|
+
setFromDefault: async (kind, from) => this.request('PUT', '/api/my-crm/v1/emails/from-defaults', { kind, from }, false),
|
|
1107
1136
|
};
|
|
1108
1137
|
/**
|
|
1109
1138
|
* Email series: emails that go to one person at a time over days, starting when something
|
|
@@ -1502,6 +1531,22 @@ export class AwesomateClient {
|
|
|
1502
1531
|
...(r.not_shown_to_you ? { notShownToYou: r.not_shown_to_you } : {}), asAt: r.as_at,
|
|
1503
1532
|
};
|
|
1504
1533
|
},
|
|
1534
|
+
/**
|
|
1535
|
+
* New leads waiting on whoever this token belongs to (the owner's token sees every one), newest
|
|
1536
|
+
* first, at most 50: open ones, and ones marked answered in the last 14 days. Each has the
|
|
1537
|
+
* person's id (`contactId`), their name where your token may read it (null otherwise), how they
|
|
1538
|
+
* came in (`door`, and `doorWords` such as 'your form') and how long it waited. To answer one,
|
|
1539
|
+
* draft a one-to-one service email to them (emails.draft with people and no list), which the
|
|
1540
|
+
* owner sends from the hub. Needs crm:read and New leads on the account (`lead_alert`).
|
|
1541
|
+
*
|
|
1542
|
+
* @example
|
|
1543
|
+
* const waiting = (await db.contacts.leads()).filter((l) => !l.answered);
|
|
1544
|
+
*/
|
|
1545
|
+
leads: async () => {
|
|
1546
|
+
if (this.appKey)
|
|
1547
|
+
throw contactsNeedAccount();
|
|
1548
|
+
return (await this.request('GET', '/api/my-crm/v1/leads')).leads;
|
|
1549
|
+
},
|
|
1505
1550
|
/**
|
|
1506
1551
|
* The person with exactly this email is changed, or added when there is none. `created: false`
|
|
1507
1552
|
* means someone already had the address, and what you sent replaced their values. Tags are
|
|
@@ -1993,6 +2038,39 @@ export class AwesomateClient {
|
|
|
1993
2038
|
async archiveLink(kind, key) {
|
|
1994
2039
|
return (await this.request('DELETE', `/api/my-crm/v1/kinds/${encodeURIComponent(kind)}/links/${encodeURIComponent(key)}`, undefined, false)).kind;
|
|
1995
2040
|
}
|
|
2041
|
+
/**
|
|
2042
|
+
* Contacts settings. `leadAlert()` reads the New leads setting: whether a new lead gives someone a
|
|
2043
|
+
* task, and who answers them. `setLeadAlert()` changes it, on the account owner's own token only
|
|
2044
|
+
* (anyone else's throws `forbidden`, server code `finish_in_hub`, and the owner changes it in the
|
|
2045
|
+
* hub at `settingsUrl`). Needs New leads on the account (`lead_alert`).
|
|
2046
|
+
*
|
|
2047
|
+
* @example
|
|
2048
|
+
* const alert = await db.setup.leadAlert();
|
|
2049
|
+
* if (alert.canChange) await db.setup.setLeadAlert({ answeredBy: 'owner' });
|
|
2050
|
+
*/
|
|
2051
|
+
setup = {
|
|
2052
|
+
/** The New leads setting. crm:read; any token may read it. */
|
|
2053
|
+
leadAlert: async () => {
|
|
2054
|
+
if (this.appKey)
|
|
2055
|
+
throw setupNeedsAccount();
|
|
2056
|
+
return leadAlertOf(await this.request('GET', '/api/my-crm/v1/leads/settings'));
|
|
2057
|
+
},
|
|
2058
|
+
/**
|
|
2059
|
+
* Change the New leads setting: `on`, and `answeredBy` ('map': the role the business map puts
|
|
2060
|
+
* in Enquiries and quotes, else the owner; 'owner'; or `{ roleId }` from the business map).
|
|
2061
|
+
* crm:write, the account owner's own token only. Answers the setting as it is now, with
|
|
2062
|
+
* `changed` false when it already was.
|
|
2063
|
+
*/
|
|
2064
|
+
setLeadAlert: async (change) => {
|
|
2065
|
+
if (this.appKey)
|
|
2066
|
+
throw setupNeedsAccount();
|
|
2067
|
+
if (change.on === undefined && change.answeredBy === undefined) {
|
|
2068
|
+
throw new AwesomateError('validation', 'setLeadAlert needs on, answeredBy, or both.', 0);
|
|
2069
|
+
}
|
|
2070
|
+
const r = await this.request('PUT', '/api/my-crm/v1/leads/settings', change, false);
|
|
2071
|
+
return { ...leadAlertOf(r), changed: r.changed };
|
|
2072
|
+
},
|
|
2073
|
+
};
|
|
1996
2074
|
/**
|
|
1997
2075
|
* Set this up for me: the hub's suggestion for one sentence about what the owner keeps track of
|
|
1998
2076
|
* ("a job management system"), as a whole setup in the owner's words (fields, stages, lists,
|
|
@@ -2221,6 +2299,25 @@ export class AwesomateClient {
|
|
|
2221
2299
|
const q = opts.page ? `?page=${encodeURIComponent(String(opts.page))}` : '';
|
|
2222
2300
|
return (await this.request('GET', `/api/my-business/v2/map/journey/steps/${encodeURIComponent(String(step))}/queue${q}`)).queue;
|
|
2223
2301
|
}
|
|
2302
|
+
/**
|
|
2303
|
+
* The business's agents in one read: every helper on the map (agents, n8n agents, automations) with
|
|
2304
|
+
* its role, level and who looks after it, what it did in the last 7 or 30 days (conversations, ones
|
|
2305
|
+
* it could not answer or passed to a person, tasks raised, decisions filed, runs and errors), what is
|
|
2306
|
+
* waiting on a person because of it, and its role's KPIs with what feeds each figure. Counts, times
|
|
2307
|
+
* and ids only, never a conversation's or task's words. A figure a kind of helper does not have is
|
|
2308
|
+
* null, never 0. hosting:read and the agentic business feature (`feature_unavailable` otherwise). The
|
|
2309
|
+
* owner's own key reads every helper (`scope` `'all'`); a person's own key reads the helpers on roles
|
|
2310
|
+
* whose KPIs they would see (`'yours'`); a narrow key reads none.
|
|
2311
|
+
*
|
|
2312
|
+
* ```ts
|
|
2313
|
+
* const { rows } = await db.businessAgents({ period: 30 });
|
|
2314
|
+
* for (const a of rows.filter((x) => x.needsPerson.count > 0)) console.log(a.label, a.needsPerson.count);
|
|
2315
|
+
* ```
|
|
2316
|
+
*/
|
|
2317
|
+
async businessAgents(opts = {}) {
|
|
2318
|
+
const q = opts.period ? `?period=${encodeURIComponent(String(opts.period))}` : '';
|
|
2319
|
+
return (await this.request('GET', `/api/my-business/v2/map/agents${q}`)).agents;
|
|
2320
|
+
}
|
|
2224
2321
|
/**
|
|
2225
2322
|
* The business's KPIs: each a number with a target and someone responsible for it, with where it
|
|
2226
2323
|
* sits, who answers for it, its light against the target for the last complete period, the period
|
|
@@ -2537,6 +2634,7 @@ const BUSINESS_DOC_KINDS = [
|
|
|
2537
2634
|
'business_summary', 'products_services', 'usps', 'ideal_customer', 'buyer_persona', 'customer_journey', 'messaging', 'voice_guide',
|
|
2538
2635
|
'faqs', 'objections', 'article_ideas', 'founder_background', 'testimonials', 'business_history', 'team_directory', 'brand_guide', 'website_brand',
|
|
2539
2636
|
];
|
|
2637
|
+
const leadAlertOf = (r) => ({ on: r.on, answeredBy: r.answeredBy, canChange: r.can_change, settingsUrl: r.settings_url });
|
|
2540
2638
|
function historyQuery(options) {
|
|
2541
2639
|
const q = new URLSearchParams();
|
|
2542
2640
|
for (const [k, v] of Object.entries(options)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awesomate/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.93.0",
|
|
4
4
|
"description": "Your own Awesomate data from Node and the browser: query contacts and app data with generated types, and sign your app's own users in",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|