posterly-mcp-server 0.54.6 → 0.55.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/README.md +45 -4
- package/dist/generated/platform-manifest.d.ts +4 -4
- package/dist/generated/platform-manifest.js +9 -4
- package/dist/index.js +15 -2
- package/dist/lib/alias-transport.js +4 -0
- package/dist/lib/api-client.d.ts +148 -0
- package/dist/lib/api-client.js +84 -0
- package/dist/lib/claude-directory-profile.js +3 -1
- package/dist/lib/format.d.ts +44 -0
- package/dist/lib/format.js +125 -5
- package/dist/lib/gbp-location-preview.d.ts +21 -0
- package/dist/lib/gbp-location-preview.js +27 -0
- package/dist/lib/google-business-review-name.d.ts +4 -0
- package/dist/lib/google-business-review-name.js +11 -0
- package/dist/lib/id-schema.d.ts +14 -0
- package/dist/lib/id-schema.js +82 -0
- package/dist/lib/id-text.d.ts +26 -0
- package/dist/lib/id-text.js +63 -0
- package/dist/lib/reply-window.d.ts +5 -0
- package/dist/lib/reply-window.js +14 -0
- package/dist/lib/service-area-text.d.ts +27 -0
- package/dist/lib/service-area-text.js +41 -0
- package/dist/lib/suggestion-accept-note.d.ts +10 -0
- package/dist/lib/suggestion-accept-note.js +17 -0
- package/dist/lib/tool-registry.js +19 -2
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/tools/audit-google-business-profile.js +7 -3
- package/dist/tools/connect-account.d.ts +2 -2
- package/dist/tools/create-connect-session.d.ts +2 -2
- package/dist/tools/create-post.d.ts +6 -6
- package/dist/tools/create-posts-batch.d.ts +4 -4
- package/dist/tools/create-webhook.d.ts +3 -3
- package/dist/tools/delete-post.d.ts +4 -4
- package/dist/tools/dismiss-suggestion.d.ts +7 -0
- package/dist/tools/dismiss-suggestion.js +21 -2
- package/dist/tools/find-slot.js +7 -4
- package/dist/tools/get-post.js +56 -5
- package/dist/tools/list-accounts.d.ts +4 -0
- package/dist/tools/list-accounts.js +25 -6
- package/dist/tools/list-analytics.d.ts +4 -0
- package/dist/tools/list-analytics.js +29 -7
- package/dist/tools/list-comments.js +13 -3
- package/dist/tools/list-conversations.d.ts +4 -4
- package/dist/tools/list-conversations.js +10 -5
- package/dist/tools/list-google-business-locations.d.ts +27 -0
- package/dist/tools/list-google-business-locations.js +35 -0
- package/dist/tools/list-google-business-media.d.ts +8 -0
- package/dist/tools/list-google-business-media.js +19 -5
- package/dist/tools/list-google-business-reviews.js +3 -2
- package/dist/tools/list-google-business-service-areas.d.ts +37 -0
- package/dist/tools/list-google-business-service-areas.js +33 -0
- package/dist/tools/list-media.js +3 -2
- package/dist/tools/list-platforms.d.ts +10 -10
- package/dist/tools/list-post-suggestions.js +5 -4
- package/dist/tools/list-posts.d.ts +8 -2
- package/dist/tools/list-posts.js +12 -2
- package/dist/tools/list-webhooks.d.ts +18 -1
- package/dist/tools/list-webhooks.js +22 -3
- package/dist/tools/list-workspace-members.js +3 -1
- package/dist/tools/manage-brands.d.ts +47 -0
- package/dist/tools/manage-brands.js +89 -0
- package/dist/tools/manage-comment.js +5 -1
- package/dist/tools/manage-google-business-location.d.ts +123 -0
- package/dist/tools/manage-google-business-location.js +97 -0
- package/dist/tools/manage-google-business-media.js +2 -0
- package/dist/tools/manage-google-business-review.js +29 -3
- package/dist/tools/manage-google-business-service-area.d.ts +74 -0
- package/dist/tools/manage-google-business-service-area.js +79 -0
- package/dist/tools/manage-webhook.d.ts +6 -6
- package/dist/tools/manage-x-posting-addon.d.ts +47 -0
- package/dist/tools/manage-x-posting-addon.js +92 -0
- package/dist/tools/trigger-platform-helper.d.ts +5 -5
- package/dist/tools/update-post.d.ts +14 -6
- package/dist/tools/update-post.js +23 -2
- package/dist/tools/upload-media.d.ts +12 -0
- package/dist/tools/upload-media.js +39 -3
- package/dist/tools/validate-post.d.ts +4 -4
- package/dist/tools/webhook-events.d.ts +2 -2
- package/dist/tools/webhook-events.js +2 -0
- package/dist/tools/whoami.d.ts +4 -0
- package/dist/tools/whoami.js +14 -6
- package/package.json +1 -1
- package/server.json +2 -2
- package/tool-annotations.json +21 -2
- package/tool-registry.json +239 -8
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
|
+
import { type ToolContext } from '../lib/tool-runtime.js';
|
|
4
|
+
type ManageLocationInput = {
|
|
5
|
+
action: 'update_hours' | 'update_attributes';
|
|
6
|
+
workspace_id?: string;
|
|
7
|
+
account_id?: number;
|
|
8
|
+
location_id?: string;
|
|
9
|
+
regular_hours?: {
|
|
10
|
+
periods: Array<{
|
|
11
|
+
open_day: string;
|
|
12
|
+
open_time: string;
|
|
13
|
+
close_day: string;
|
|
14
|
+
close_time: string;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
attributes?: Array<{
|
|
18
|
+
name: string;
|
|
19
|
+
value_type: 'BOOL' | 'URL' | 'ENUM';
|
|
20
|
+
values: Array<boolean | string>;
|
|
21
|
+
}>;
|
|
22
|
+
confirm?: boolean;
|
|
23
|
+
preview_id?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const manageGoogleBusinessLocationTool: {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: z.ZodObject<{
|
|
29
|
+
action: z.ZodEnum<["update_hours", "update_attributes"]>;
|
|
30
|
+
workspace_id: z.ZodOptional<z.ZodString>;
|
|
31
|
+
account_id: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
location_id: z.ZodOptional<z.ZodString>;
|
|
33
|
+
regular_hours: z.ZodOptional<z.ZodObject<{
|
|
34
|
+
periods: z.ZodArray<z.ZodObject<{
|
|
35
|
+
open_day: z.ZodString;
|
|
36
|
+
open_time: z.ZodString;
|
|
37
|
+
close_day: z.ZodString;
|
|
38
|
+
close_time: z.ZodString;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
open_day: string;
|
|
41
|
+
open_time: string;
|
|
42
|
+
close_day: string;
|
|
43
|
+
close_time: string;
|
|
44
|
+
}, {
|
|
45
|
+
open_day: string;
|
|
46
|
+
open_time: string;
|
|
47
|
+
close_day: string;
|
|
48
|
+
close_time: string;
|
|
49
|
+
}>, "many">;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
periods: {
|
|
52
|
+
open_day: string;
|
|
53
|
+
open_time: string;
|
|
54
|
+
close_day: string;
|
|
55
|
+
close_time: string;
|
|
56
|
+
}[];
|
|
57
|
+
}, {
|
|
58
|
+
periods: {
|
|
59
|
+
open_day: string;
|
|
60
|
+
open_time: string;
|
|
61
|
+
close_day: string;
|
|
62
|
+
close_time: string;
|
|
63
|
+
}[];
|
|
64
|
+
}>>;
|
|
65
|
+
attributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
66
|
+
name: z.ZodString;
|
|
67
|
+
value_type: z.ZodEnum<["BOOL", "URL", "ENUM"]>;
|
|
68
|
+
values: z.ZodArray<z.ZodUnion<[z.ZodBoolean, z.ZodString]>, "many">;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
values: (string | boolean)[];
|
|
71
|
+
name: string;
|
|
72
|
+
value_type: "URL" | "BOOL" | "ENUM";
|
|
73
|
+
}, {
|
|
74
|
+
values: (string | boolean)[];
|
|
75
|
+
name: string;
|
|
76
|
+
value_type: "URL" | "BOOL" | "ENUM";
|
|
77
|
+
}>, "many">>;
|
|
78
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
preview_id: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, "strip", z.ZodTypeAny, {
|
|
81
|
+
action: "update_hours" | "update_attributes";
|
|
82
|
+
account_id?: number | undefined;
|
|
83
|
+
workspace_id?: string | undefined;
|
|
84
|
+
confirm?: boolean | undefined;
|
|
85
|
+
preview_id?: string | undefined;
|
|
86
|
+
location_id?: string | undefined;
|
|
87
|
+
regular_hours?: {
|
|
88
|
+
periods: {
|
|
89
|
+
open_day: string;
|
|
90
|
+
open_time: string;
|
|
91
|
+
close_day: string;
|
|
92
|
+
close_time: string;
|
|
93
|
+
}[];
|
|
94
|
+
} | undefined;
|
|
95
|
+
attributes?: {
|
|
96
|
+
values: (string | boolean)[];
|
|
97
|
+
name: string;
|
|
98
|
+
value_type: "URL" | "BOOL" | "ENUM";
|
|
99
|
+
}[] | undefined;
|
|
100
|
+
}, {
|
|
101
|
+
action: "update_hours" | "update_attributes";
|
|
102
|
+
account_id?: number | undefined;
|
|
103
|
+
workspace_id?: string | undefined;
|
|
104
|
+
confirm?: boolean | undefined;
|
|
105
|
+
preview_id?: string | undefined;
|
|
106
|
+
location_id?: string | undefined;
|
|
107
|
+
regular_hours?: {
|
|
108
|
+
periods: {
|
|
109
|
+
open_day: string;
|
|
110
|
+
open_time: string;
|
|
111
|
+
close_day: string;
|
|
112
|
+
close_time: string;
|
|
113
|
+
}[];
|
|
114
|
+
} | undefined;
|
|
115
|
+
attributes?: {
|
|
116
|
+
values: (string | boolean)[];
|
|
117
|
+
name: string;
|
|
118
|
+
value_type: "URL" | "BOOL" | "ENUM";
|
|
119
|
+
}[] | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
execute(client: PosterlyClient, input: ManageLocationInput, ctx: ToolContext): Promise<string>;
|
|
122
|
+
};
|
|
123
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { code, mdKeyValue, mdSection } from '../lib/format.js';
|
|
3
|
+
import { omitKeys, previewThenConfirm, readFailedNote, readForPreview, validateArgs } from '../lib/tool-runtime.js';
|
|
4
|
+
import { GBP_CLOSED_DAYS_NOTE, gbpAttributeLines, gbpCurrentAttributesFor, gbpPeriodLines } from '../lib/gbp-location-preview.js';
|
|
5
|
+
const LOCATION_ID_DESCRIPTION = 'Google Business numeric location id (the location_id/platform_user_id from list_accounts, e.g. "197940849675145390"). NOT the ChIJ... Place ID from list_google_business_reviews view=review_link. Prefer account_id.';
|
|
6
|
+
const periodSchema = z.object({
|
|
7
|
+
open_day: z.string(),
|
|
8
|
+
open_time: z.string(),
|
|
9
|
+
close_day: z.string(),
|
|
10
|
+
close_time: z.string(),
|
|
11
|
+
});
|
|
12
|
+
const attributeSchema = z.object({
|
|
13
|
+
name: z.string(),
|
|
14
|
+
value_type: z.enum(['BOOL', 'URL', 'ENUM']),
|
|
15
|
+
values: z.array(z.union([z.boolean(), z.string()])).min(1).max(5),
|
|
16
|
+
});
|
|
17
|
+
function locationRows(input) {
|
|
18
|
+
return [
|
|
19
|
+
['Account ID', input.account_id !== undefined ? code(input.account_id) : undefined],
|
|
20
|
+
['Location ID', input.location_id ? code(input.location_id) : undefined],
|
|
21
|
+
['Workspace', input.workspace_id ? code(input.workspace_id) : undefined],
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
async function readCurrentLocation(client, input) {
|
|
25
|
+
return readForPreview(() => client.listGoogleBusinessLocation({
|
|
26
|
+
workspace_id: input.workspace_id,
|
|
27
|
+
account_id: input.account_id,
|
|
28
|
+
location_id: input.location_id,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function locationReadNote(error) {
|
|
32
|
+
return /switched off/i.test(error)
|
|
33
|
+
? '_Location edits are switched off, so the current values were not read and a confirm changes nothing._'
|
|
34
|
+
: readFailedNote(error);
|
|
35
|
+
}
|
|
36
|
+
export const manageGoogleBusinessLocationTool = {
|
|
37
|
+
name: 'manage_google_business_location',
|
|
38
|
+
description: 'Change regular opening hours or attributes on a Google Business location. action=update_hours sends regular_hours.periods with open_day, close_day, open_time, and close_time as HH:MM. action=update_attributes sends attributes with a name like attributes/has_wifi and value_type BOOL, URL, or ENUM. Both use preview then confirm: call without confirm to get a preview and preview_id, show it, then call again with confirm=true and that preview_id. Stays off until location edits are switched on. A confirm while it is off changes nothing and does not call Google. This uses the same business management connection as posting. It does not change the business name, address, phone, or website.',
|
|
39
|
+
inputSchema: z.object({
|
|
40
|
+
action: z.enum(['update_hours', 'update_attributes']).describe('update_hours or update_attributes.'),
|
|
41
|
+
workspace_id: z.string().optional().describe('Filter to a workspace ID from whoami.'),
|
|
42
|
+
account_id: z.number().int().positive().optional().describe('Google Business account ID from list_accounts.'),
|
|
43
|
+
location_id: z.string().optional().describe(LOCATION_ID_DESCRIPTION),
|
|
44
|
+
regular_hours: z.object({ periods: z.array(periodSchema).min(1).max(14) }).optional().describe('update_hours: opening periods. Days are MONDAY-SUNDAY. Times are HH:MM.'),
|
|
45
|
+
attributes: z.array(attributeSchema).min(1).max(20).optional().describe('update_attributes: attributes to set. URL values must be https. Names look like attributes/has_wifi.'),
|
|
46
|
+
confirm: z.boolean().optional().describe('Leave out to get a preview; true only with the preview_id after the user approved it.'),
|
|
47
|
+
preview_id: z.string().optional().describe('The preview_id from the preview call. Required with confirm: true.'),
|
|
48
|
+
}),
|
|
49
|
+
async execute(client, input, ctx) {
|
|
50
|
+
const { mode, args } = validateArgs(ctx, 'manage_google_business_location', input);
|
|
51
|
+
const call = args;
|
|
52
|
+
if (mode === 'update_attributes') {
|
|
53
|
+
return previewThenConfirm({
|
|
54
|
+
tool: 'manage_google_business_location',
|
|
55
|
+
action: 'update_attributes',
|
|
56
|
+
args,
|
|
57
|
+
nonce: true,
|
|
58
|
+
legacyRefusal: 'Refusing to change Google Business attributes without confirm=true after explicit user confirmation.',
|
|
59
|
+
ctx,
|
|
60
|
+
describe: async () => {
|
|
61
|
+
const read = await readCurrentLocation(client, call);
|
|
62
|
+
const current = read.ok && Array.isArray(read.data?.attributes) ? gbpCurrentAttributesFor(read.data.attributes, call.attributes) : null;
|
|
63
|
+
return [
|
|
64
|
+
mdSection('Current values', current ? gbpAttributeLines(current, 'None of these attributes is set now.') : locationReadNote(read.ok ? 'no attributes returned' : read.error)),
|
|
65
|
+
mdSection('Attributes to set', [gbpAttributeLines(call.attributes, 'No attributes were sent.'), '', mdKeyValue(locationRows(call))].join('\n')),
|
|
66
|
+
'This replaces those attributes on the public Google Business profile. Other attributes are left as they are. Nothing is sent until you confirm, and the edit stays off until location edits are switched on.',
|
|
67
|
+
].join('\n\n');
|
|
68
|
+
},
|
|
69
|
+
run: async () => {
|
|
70
|
+
const result = await client.updateGoogleBusinessAttributes(omitKeys(call, ['action', 'confirm', 'preview_id']));
|
|
71
|
+
return result.success ? 'Google Business attributes updated.' : (result.error || 'Google Business attributes were not updated.');
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return previewThenConfirm({
|
|
76
|
+
tool: 'manage_google_business_location',
|
|
77
|
+
action: 'update_hours',
|
|
78
|
+
args,
|
|
79
|
+
nonce: true,
|
|
80
|
+
legacyRefusal: 'Refusing to change Google Business hours without confirm=true after explicit user confirmation.',
|
|
81
|
+
ctx,
|
|
82
|
+
describe: async () => {
|
|
83
|
+
const read = await readCurrentLocation(client, call);
|
|
84
|
+
const current = read.ok && Array.isArray(read.data?.regular_hours?.periods) ? read.data.regular_hours.periods : null;
|
|
85
|
+
return [
|
|
86
|
+
mdSection('Current regular hours', current ? gbpPeriodLines(current, 'No regular hours are saved now.') : locationReadNote(read.ok ? 'no hours returned' : read.error)),
|
|
87
|
+
mdSection('Regular hours to set', [gbpPeriodLines(call.regular_hours?.periods, 'No opening periods were sent.'), '', GBP_CLOSED_DAYS_NOTE, '', mdKeyValue(locationRows(call))].join('\n')),
|
|
88
|
+
'This replaces the regular opening hours on the public Google Business profile. Nothing is sent until you confirm, and the edit stays off until location edits are switched on.',
|
|
89
|
+
].join('\n\n');
|
|
90
|
+
},
|
|
91
|
+
run: async () => {
|
|
92
|
+
const result = await client.updateGoogleBusinessHours(omitKeys(call, ['action', 'confirm', 'preview_id']));
|
|
93
|
+
return result.success ? 'Google Business hours updated.' : (result.error || 'Google Business hours were not updated.');
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -85,6 +85,8 @@ export const manageGoogleBusinessMediaTool = {
|
|
|
85
85
|
['Resource name', code(String(item.name))],
|
|
86
86
|
['Type', item.mediaFormat === 'VIDEO' ? 'video' : 'photo'],
|
|
87
87
|
['Category', item.category || 'uncategorised'],
|
|
88
|
+
['Image', item.googleUrl || item.thumbnailUrl || undefined],
|
|
89
|
+
['Added', item.createTime || undefined],
|
|
88
90
|
...locationRows(call),
|
|
89
91
|
]))
|
|
90
92
|
: [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { code, mdKeyValue, mdQuote, mdSection } from '../lib/format.js';
|
|
3
|
-
import {
|
|
3
|
+
import { reviewNameFromListItem, reviewReplyComment } from '../lib/google-business-review-name.js';
|
|
4
|
+
import { omitKeys, previewThenConfirm, readForPreview, validateArgs } from '../lib/tool-runtime.js';
|
|
4
5
|
const LOCATION_ID_DESCRIPTION = 'Google Business numeric location id (the location_id/platform_user_id from list_accounts, e.g. "197940849675145390"). NOT the ChIJ... Place ID from list_google_business_reviews view=review_link. Prefer account_id.';
|
|
5
6
|
const LEGACY_LOCATION = {
|
|
6
7
|
workspace_id: z.string().optional(),
|
|
@@ -11,6 +12,31 @@ const LEGACY_LOCATION = {
|
|
|
11
12
|
function payloadOf(input) {
|
|
12
13
|
return omitKeys(input, ['action', 'confirm', 'preview_id']);
|
|
13
14
|
}
|
|
15
|
+
async function lookupReview(client, call) {
|
|
16
|
+
const read = await readForPreview(() => client.listGoogleBusinessReviews({
|
|
17
|
+
workspace_id: call.workspace_id,
|
|
18
|
+
account_id: call.account_id,
|
|
19
|
+
location_id: call.location_id,
|
|
20
|
+
limit: 200,
|
|
21
|
+
}));
|
|
22
|
+
if (!read.ok || !Array.isArray(read.data?.reviews))
|
|
23
|
+
return null;
|
|
24
|
+
const wanted = String(call.review_name || '');
|
|
25
|
+
return read.data.reviews.find((review) => reviewNameFromListItem(review) === wanted || review?.name === wanted) || null;
|
|
26
|
+
}
|
|
27
|
+
function reviewPreviewRows(call, review) {
|
|
28
|
+
if (!review)
|
|
29
|
+
return [['Review', code(String(call.review_name))], ...locationRows(call)];
|
|
30
|
+
const existing = reviewReplyComment(review);
|
|
31
|
+
return [
|
|
32
|
+
['Reviewer', review.reviewer?.displayName || 'Anonymous'],
|
|
33
|
+
['Rating', review.starRating ? `${review.starRating} stars` : 'unrated'],
|
|
34
|
+
['Review', review.comment ? String(review.comment).replace(/\s+/g, ' ').trim() : '(rating only)'],
|
|
35
|
+
['Existing reply', existing || (review.reviewReply ? 'replied' : 'none')],
|
|
36
|
+
['Review', code(String(call.review_name))],
|
|
37
|
+
...locationRows(call),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
14
40
|
function locationRows(input) {
|
|
15
41
|
return [
|
|
16
42
|
['Account ID', input.account_id !== undefined ? code(input.account_id) : undefined],
|
|
@@ -74,7 +100,7 @@ export const manageGoogleBusinessReviewTool = {
|
|
|
74
100
|
legacyRefusal: 'Refusing to delete a Google review reply without confirm=true after explicit user confirmation.',
|
|
75
101
|
ctx,
|
|
76
102
|
describe: async () => [
|
|
77
|
-
mdSection('Review', mdKeyValue(
|
|
103
|
+
mdSection('Review', mdKeyValue(reviewPreviewRows(call, await lookupReview(client, call)))),
|
|
78
104
|
'This deletes the owner reply from this review on Google. The review itself stays.',
|
|
79
105
|
].join('\n\n'),
|
|
80
106
|
run: async () => {
|
|
@@ -91,7 +117,7 @@ export const manageGoogleBusinessReviewTool = {
|
|
|
91
117
|
legacyRefusal: 'Refusing to post a Google review reply without confirm=true after explicit user confirmation.',
|
|
92
118
|
ctx,
|
|
93
119
|
describe: async () => [
|
|
94
|
-
mdSection('Review', mdKeyValue(
|
|
120
|
+
mdSection('Review', mdKeyValue(reviewPreviewRows(call, await lookupReview(client, call)))),
|
|
95
121
|
mdSection('Owner reply to post', mdQuote(String(call.comment ?? ''))),
|
|
96
122
|
'This posts publicly on Google as the business owner and replaces any existing owner reply on this review.',
|
|
97
123
|
].join('\n\n'),
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
|
+
import { type ToolContext } from '../lib/tool-runtime.js';
|
|
4
|
+
type Place = {
|
|
5
|
+
place_id: string;
|
|
6
|
+
place_name: string;
|
|
7
|
+
};
|
|
8
|
+
type UpdateInput = {
|
|
9
|
+
action: 'update';
|
|
10
|
+
workspace_id?: string;
|
|
11
|
+
account_id?: number;
|
|
12
|
+
location_id?: string;
|
|
13
|
+
business_type?: 'CUSTOMER_LOCATION_ONLY' | 'CUSTOMER_AND_BUSINESS_LOCATION';
|
|
14
|
+
region_code?: string;
|
|
15
|
+
places?: Place[];
|
|
16
|
+
clear_storefront_address?: boolean;
|
|
17
|
+
confirm?: boolean;
|
|
18
|
+
preview_id?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const manageGoogleBusinessServiceAreaTool: {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
inputSchema: z.ZodObject<{
|
|
24
|
+
action: z.ZodEnum<["update"]>;
|
|
25
|
+
workspace_id: z.ZodOptional<z.ZodString>;
|
|
26
|
+
account_id: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
location_id: z.ZodOptional<z.ZodString>;
|
|
28
|
+
business_type: z.ZodOptional<z.ZodEnum<["CUSTOMER_LOCATION_ONLY", "CUSTOMER_AND_BUSINESS_LOCATION"]>>;
|
|
29
|
+
region_code: z.ZodOptional<z.ZodString>;
|
|
30
|
+
places: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
31
|
+
place_id: z.ZodString;
|
|
32
|
+
place_name: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
place_id: string;
|
|
35
|
+
place_name: string;
|
|
36
|
+
}, {
|
|
37
|
+
place_id: string;
|
|
38
|
+
place_name: string;
|
|
39
|
+
}>, "many">>;
|
|
40
|
+
clear_storefront_address: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
preview_id: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
action: "update";
|
|
45
|
+
account_id?: number | undefined;
|
|
46
|
+
workspace_id?: string | undefined;
|
|
47
|
+
confirm?: boolean | undefined;
|
|
48
|
+
preview_id?: string | undefined;
|
|
49
|
+
location_id?: string | undefined;
|
|
50
|
+
region_code?: string | undefined;
|
|
51
|
+
places?: {
|
|
52
|
+
place_id: string;
|
|
53
|
+
place_name: string;
|
|
54
|
+
}[] | undefined;
|
|
55
|
+
business_type?: "CUSTOMER_LOCATION_ONLY" | "CUSTOMER_AND_BUSINESS_LOCATION" | undefined;
|
|
56
|
+
clear_storefront_address?: boolean | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
action: "update";
|
|
59
|
+
account_id?: number | undefined;
|
|
60
|
+
workspace_id?: string | undefined;
|
|
61
|
+
confirm?: boolean | undefined;
|
|
62
|
+
preview_id?: string | undefined;
|
|
63
|
+
location_id?: string | undefined;
|
|
64
|
+
region_code?: string | undefined;
|
|
65
|
+
places?: {
|
|
66
|
+
place_id: string;
|
|
67
|
+
place_name: string;
|
|
68
|
+
}[] | undefined;
|
|
69
|
+
business_type?: "CUSTOMER_LOCATION_ONLY" | "CUSTOMER_AND_BUSINESS_LOCATION" | undefined;
|
|
70
|
+
clear_storefront_address?: boolean | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
execute(client: PosterlyClient, input: UpdateInput, ctx: ToolContext): Promise<string>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { code, mdKeyValue, mdSection } from '../lib/format.js';
|
|
3
|
+
import { formatGoogleBusinessServiceArea } from '../lib/service-area-text.js';
|
|
4
|
+
import { omitKeys, previewThenConfirm, readFailedNote, readForPreview, validateArgs } from '../lib/tool-runtime.js';
|
|
5
|
+
const LOCATION_ID_DESCRIPTION = 'Google Business numeric location id (the location_id/platform_user_id from list_accounts, e.g. "197940849675145390"). NOT the ChIJ... Place ID from list_google_business_reviews view=review_link. Prefer account_id.';
|
|
6
|
+
const placeSchema = z.object({
|
|
7
|
+
place_id: z.string(),
|
|
8
|
+
place_name: z.string(),
|
|
9
|
+
});
|
|
10
|
+
export const manageGoogleBusinessServiceAreaTool = {
|
|
11
|
+
name: 'manage_google_business_service_area',
|
|
12
|
+
description: 'Replace the service areas on a Google Business location. action=update sends the full list (1 to 20 places, each with place_id and place_name from list_google_business_service_areas view=places or a known region Place ID). business_type is CUSTOMER_AND_BUSINESS_LOCATION (customers can visit, and you also travel) or CUSTOMER_LOCATION_ONLY (you only travel to customers). CUSTOMER_LOCATION_ONLY needs region_code when Google has not set one, and clear_storefront_address=true when a street address is still on the listing. The country cannot be changed once set. Preview then confirm: call without confirm to get a preview and preview_id, show it, then call again with confirm=true and that preview_id. Saving the same list again is safe.',
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
action: z.enum(['update']).describe('update: replace the service area list.'),
|
|
15
|
+
workspace_id: z.string().optional(),
|
|
16
|
+
account_id: z.number().int().positive().optional().describe('Google Business account ID from list_accounts.'),
|
|
17
|
+
location_id: z.string().optional().describe(LOCATION_ID_DESCRIPTION),
|
|
18
|
+
business_type: z.enum(['CUSTOMER_LOCATION_ONLY', 'CUSTOMER_AND_BUSINESS_LOCATION']).optional().describe('CUSTOMER_LOCATION_ONLY travels to customers. CUSTOMER_AND_BUSINESS_LOCATION also has a storefront.'),
|
|
19
|
+
region_code: z.string().optional().describe('Two-letter country code. Required for customer-only listings that do not already have one. Immutable once set.'),
|
|
20
|
+
places: z.array(placeSchema).max(20).optional().describe('The full replacement list, 1 to 20 areas. Each item needs place_id and place_name.'),
|
|
21
|
+
clear_storefront_address: z.boolean().optional().describe('Set true only when switching to customer-only. Google requires the street address to be removed from the listing in the same update; it is not kept, so adding it back means entering it again.'),
|
|
22
|
+
confirm: z.boolean().optional().describe('Leave out to get a preview; true only with the preview_id after the user approved it.'),
|
|
23
|
+
preview_id: z.string().optional().describe('The preview_id from the preview call. Required with confirm: true.'),
|
|
24
|
+
}),
|
|
25
|
+
async execute(client, input, ctx) {
|
|
26
|
+
const { args } = validateArgs(ctx, 'manage_google_business_service_area', input);
|
|
27
|
+
const call = args;
|
|
28
|
+
return previewThenConfirm({
|
|
29
|
+
tool: 'manage_google_business_service_area',
|
|
30
|
+
action: 'update',
|
|
31
|
+
args,
|
|
32
|
+
nonce: false,
|
|
33
|
+
legacyRefusal: 'Refusing to update Google Business service areas without confirm=true after explicit user confirmation.',
|
|
34
|
+
ctx,
|
|
35
|
+
describe: async () => {
|
|
36
|
+
const placeLines = (list, empty) => {
|
|
37
|
+
const rows = Array.isArray(list) ? list : [];
|
|
38
|
+
return rows.length
|
|
39
|
+
? rows.map((place) => `- ${place.place_name} :: ${place.place_id}`).join('\n')
|
|
40
|
+
: empty;
|
|
41
|
+
};
|
|
42
|
+
// The update replaces the whole list, so show what it replaces.
|
|
43
|
+
const read = await readForPreview(() => client.getGoogleBusinessServiceArea({
|
|
44
|
+
workspace_id: call.workspace_id,
|
|
45
|
+
account_id: call.account_id,
|
|
46
|
+
location_id: call.location_id,
|
|
47
|
+
}));
|
|
48
|
+
const current = read.ok ? read.data?.service_area : null;
|
|
49
|
+
return [
|
|
50
|
+
current
|
|
51
|
+
? mdSection('Current service areas', [
|
|
52
|
+
mdKeyValue([
|
|
53
|
+
['Business type', current.business_type || 'not set'],
|
|
54
|
+
['Country', current.region_code || 'not set'],
|
|
55
|
+
]),
|
|
56
|
+
placeLines(current.places, 'No areas are set.'),
|
|
57
|
+
].join('\n\n'))
|
|
58
|
+
: readFailedNote(read.ok ? 'no service area returned' : read.error),
|
|
59
|
+
mdSection('Service areas to save', [
|
|
60
|
+
mdKeyValue([
|
|
61
|
+
['Business type', call.business_type],
|
|
62
|
+
['Country', call.region_code || 'unchanged'],
|
|
63
|
+
['Remove street address', call.clear_storefront_address === true ? 'yes, it is deleted from the listing' : 'no'],
|
|
64
|
+
['Account ID', call.account_id !== undefined ? code(call.account_id) : undefined],
|
|
65
|
+
['Location ID', call.location_id ? code(call.location_id) : undefined],
|
|
66
|
+
['Workspace', call.workspace_id ? code(call.workspace_id) : undefined],
|
|
67
|
+
]),
|
|
68
|
+
placeLines(call.places, 'No areas in this request.'),
|
|
69
|
+
].join('\n\n')),
|
|
70
|
+
'This replaces the public service areas on Google. Google allows up to 20 towns or postcodes. Edits can take up to 48 hours to show.',
|
|
71
|
+
].join('\n\n');
|
|
72
|
+
},
|
|
73
|
+
run: async () => {
|
|
74
|
+
const result = await client.updateGoogleBusinessServiceArea(omitKeys(call, ['action', 'confirm', 'preview_id']));
|
|
75
|
+
return formatGoogleBusinessServiceArea(result);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -19,7 +19,7 @@ export declare const manageWebhookTool: {
|
|
|
19
19
|
action: z.ZodEnum<["update", "delete", "test"]>;
|
|
20
20
|
webhook_id: z.ZodString;
|
|
21
21
|
url: z.ZodOptional<z.ZodString>;
|
|
22
|
-
events: z.ZodOptional<z.ZodArray<z.ZodEnum<["webhook.test", "post.created", "post.updated", "post.deleted", "post.publishing", "post.published", "post.failed", "account.disconnected", "analytics.synced", "approval.requested", "approval.approved", "approval.changes_requested", "approval.rejected", "approval.commented"]>, "many">>;
|
|
22
|
+
events: z.ZodOptional<z.ZodArray<z.ZodEnum<["webhook.test", "post.created", "post.updated", "post.deleted", "post.publishing", "post.published", "post.failed", "account.disconnected", "account.needs_reconnect", "account.reconnected", "analytics.synced", "approval.requested", "approval.approved", "approval.changes_requested", "approval.rejected", "approval.commented"]>, "many">>;
|
|
23
23
|
workspace_id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
24
24
|
description: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
25
25
|
is_active: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -34,7 +34,7 @@ export declare const manageWebhookTool: {
|
|
|
34
34
|
preview_id?: string | undefined;
|
|
35
35
|
url?: string | undefined;
|
|
36
36
|
is_active?: boolean | undefined;
|
|
37
|
-
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
37
|
+
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "account.needs_reconnect" | "account.reconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
38
38
|
}, {
|
|
39
39
|
action: "update" | "delete" | "test";
|
|
40
40
|
webhook_id: string;
|
|
@@ -44,14 +44,14 @@ export declare const manageWebhookTool: {
|
|
|
44
44
|
preview_id?: string | undefined;
|
|
45
45
|
url?: string | undefined;
|
|
46
46
|
is_active?: boolean | undefined;
|
|
47
|
-
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
47
|
+
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "account.needs_reconnect" | "account.reconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
48
48
|
}>;
|
|
49
49
|
/** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
|
|
50
50
|
legacySchemas: {
|
|
51
51
|
update_webhook: z.ZodObject<{
|
|
52
52
|
webhook_id: z.ZodString;
|
|
53
53
|
url: z.ZodOptional<z.ZodString>;
|
|
54
|
-
events: z.ZodOptional<z.ZodArray<z.ZodEnum<["webhook.test", "post.created", "post.updated", "post.deleted", "post.publishing", "post.published", "post.failed", "account.disconnected", "analytics.synced", "approval.requested", "approval.approved", "approval.changes_requested", "approval.rejected", "approval.commented"]>, "many">>;
|
|
54
|
+
events: z.ZodOptional<z.ZodArray<z.ZodEnum<["webhook.test", "post.created", "post.updated", "post.deleted", "post.publishing", "post.published", "post.failed", "account.disconnected", "account.needs_reconnect", "account.reconnected", "analytics.synced", "approval.requested", "approval.approved", "approval.changes_requested", "approval.rejected", "approval.commented"]>, "many">>;
|
|
55
55
|
workspace_id: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
56
56
|
description: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNull]>>;
|
|
57
57
|
is_active: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -63,7 +63,7 @@ export declare const manageWebhookTool: {
|
|
|
63
63
|
description?: string | null | undefined;
|
|
64
64
|
url?: string | undefined;
|
|
65
65
|
is_active?: boolean | undefined;
|
|
66
|
-
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
66
|
+
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "account.needs_reconnect" | "account.reconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
confirm: true;
|
|
69
69
|
webhook_id: string;
|
|
@@ -71,7 +71,7 @@ export declare const manageWebhookTool: {
|
|
|
71
71
|
description?: string | null | undefined;
|
|
72
72
|
url?: string | undefined;
|
|
73
73
|
is_active?: boolean | undefined;
|
|
74
|
-
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
74
|
+
events?: ("webhook.test" | "post.created" | "post.updated" | "post.deleted" | "post.publishing" | "post.published" | "post.failed" | "account.disconnected" | "account.needs_reconnect" | "account.reconnected" | "analytics.synced" | "approval.requested" | "approval.approved" | "approval.changes_requested" | "approval.rejected" | "approval.commented")[] | undefined;
|
|
75
75
|
}>;
|
|
76
76
|
delete_webhook: z.ZodObject<{
|
|
77
77
|
webhook_id: z.ZodString;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PosterlyClient } from '../lib/api-client.js';
|
|
3
|
+
import { type ToolContext } from '../lib/tool-runtime.js';
|
|
4
|
+
type BuyInput = {
|
|
5
|
+
action: 'buy';
|
|
6
|
+
plan_code?: 'x_posts_100' | 'x_posts_250' | 'x_posts_500';
|
|
7
|
+
workspace_id?: string;
|
|
8
|
+
expected_addon_status?: string;
|
|
9
|
+
expected_plan_code?: string | null;
|
|
10
|
+
expected_price_usd?: number | null;
|
|
11
|
+
confirm?: boolean;
|
|
12
|
+
preview_id?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const manageXPostingAddonTool: {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
inputSchema: z.ZodObject<{
|
|
18
|
+
action: z.ZodEnum<["buy"]>;
|
|
19
|
+
plan_code: z.ZodOptional<z.ZodEnum<["x_posts_100", "x_posts_250", "x_posts_500"]>>;
|
|
20
|
+
workspace_id: z.ZodOptional<z.ZodString>;
|
|
21
|
+
expected_addon_status: z.ZodOptional<z.ZodString>;
|
|
22
|
+
expected_plan_code: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
expected_price_usd: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
24
|
+
confirm: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
preview_id: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
action: "buy";
|
|
28
|
+
workspace_id?: string | undefined;
|
|
29
|
+
confirm?: boolean | undefined;
|
|
30
|
+
preview_id?: string | undefined;
|
|
31
|
+
plan_code?: "x_posts_100" | "x_posts_250" | "x_posts_500" | undefined;
|
|
32
|
+
expected_addon_status?: string | undefined;
|
|
33
|
+
expected_plan_code?: string | null | undefined;
|
|
34
|
+
expected_price_usd?: number | null | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
action: "buy";
|
|
37
|
+
workspace_id?: string | undefined;
|
|
38
|
+
confirm?: boolean | undefined;
|
|
39
|
+
preview_id?: string | undefined;
|
|
40
|
+
plan_code?: "x_posts_100" | "x_posts_250" | "x_posts_500" | undefined;
|
|
41
|
+
expected_addon_status?: string | undefined;
|
|
42
|
+
expected_plan_code?: string | null | undefined;
|
|
43
|
+
expected_price_usd?: number | null | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
execute(client: PosterlyClient, input: BuyInput, ctx: ToolContext): Promise<string>;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { mdKeyValue, mdSection, mdTitle } from '../lib/format.js';
|
|
3
|
+
import { previewThenConfirm, readForPreview, validateArgs } from '../lib/tool-runtime.js';
|
|
4
|
+
const X_ADDON_DESCRIPTION = 'Buy an X posting add-on. action=buy: plan_code is x_posts_100 ($8/month, 100 extra posts), x_posts_250 ($18/month, 250), or x_posts_500 ($35/month, 500). Call without confirm to see the price. Show that price to the user. Nothing is charged on the preview. Then call again with confirm=true, the preview_id, and expected_addon_status, expected_plan_code, and expected_price_usd from the preview. Confirming returns a Stripe Checkout link. The card is charged only after the user pays on that page. If an add-on is already active, confirming opens the billing page for the workspace owner and does not buy a second plan. Read the allowance with get_x_posting_quota. Owner or admin. billing:write.';
|
|
5
|
+
function formatQuote(quote) {
|
|
6
|
+
const price = quote.price_usd == null ? 'n/a' : `$${quote.price_usd} per month`;
|
|
7
|
+
return [
|
|
8
|
+
mdTitle(quote.mode === 'portal' ? 'X posting add-on: billing page' : 'X posting add-on quote'),
|
|
9
|
+
quote.effect || '',
|
|
10
|
+
mdSection('Quote', mdKeyValue([
|
|
11
|
+
['Plan', quote.plan_name || quote.plan_code || 'none yet'],
|
|
12
|
+
['Price', price],
|
|
13
|
+
['Extra posts', quote.monthly_posts ?? 'n/a'],
|
|
14
|
+
['Charged now', 'no'],
|
|
15
|
+
['Current add-on status', quote.current_addon_status],
|
|
16
|
+
])),
|
|
17
|
+
'Nothing is charged until the Stripe page is paid.',
|
|
18
|
+
mdSection('Fields to repeat on confirm', [
|
|
19
|
+
`expected_addon_status: ${quote.current_addon_status}`,
|
|
20
|
+
`expected_plan_code: ${quote.current_plan_code == null ? 'null' : quote.current_plan_code}`,
|
|
21
|
+
`expected_price_usd: ${quote.price_usd == null ? 'null' : quote.price_usd}`,
|
|
22
|
+
].join('\n')),
|
|
23
|
+
].filter(Boolean).join('\n\n');
|
|
24
|
+
}
|
|
25
|
+
export const manageXPostingAddonTool = {
|
|
26
|
+
name: 'manage_x_posting_addon',
|
|
27
|
+
description: X_ADDON_DESCRIPTION,
|
|
28
|
+
inputSchema: z.object({
|
|
29
|
+
action: z.enum(['buy']).describe('buy: quote an X posting add-on, then open Checkout after the user agrees.'),
|
|
30
|
+
plan_code: z.enum(['x_posts_100', 'x_posts_250', 'x_posts_500']).optional().describe('Which add-on to buy. Not used when one is already active.'),
|
|
31
|
+
workspace_id: z.string().optional().describe('Workspace ID from whoami, when the key is not already scoped.'),
|
|
32
|
+
expected_addon_status: z.string().optional().describe('From the preview. The add-on status the quote was based on.'),
|
|
33
|
+
expected_plan_code: z.string().nullable().optional().describe('From the preview. The current plan code, or null when there is none.'),
|
|
34
|
+
expected_price_usd: z.number().nullable().optional().describe('From the preview. The monthly price in dollars, or null.'),
|
|
35
|
+
confirm: z.boolean().optional().describe('True only after the user agrees, with the preview_id.'),
|
|
36
|
+
preview_id: z.string().optional().describe('The preview_id from the preview call.'),
|
|
37
|
+
}),
|
|
38
|
+
async execute(client, input, ctx) {
|
|
39
|
+
const { args } = validateArgs(ctx, 'manage_x_posting_addon', input);
|
|
40
|
+
const call = args;
|
|
41
|
+
let quote = null;
|
|
42
|
+
let previewArgs = args;
|
|
43
|
+
if (call.confirm !== true) {
|
|
44
|
+
const read = await readForPreview(() => client.quoteXPostingAddon({
|
|
45
|
+
...(call.plan_code ? { plan_code: call.plan_code } : {}),
|
|
46
|
+
...(call.workspace_id ? { workspace_id: call.workspace_id } : {}),
|
|
47
|
+
}));
|
|
48
|
+
if (!read.ok) {
|
|
49
|
+
throw new Error([
|
|
50
|
+
'No preview: this add-on cannot be started right now.',
|
|
51
|
+
read.error,
|
|
52
|
+
'Nothing was charged and no preview_id was issued.',
|
|
53
|
+
].join('\n\n'));
|
|
54
|
+
}
|
|
55
|
+
quote = read.data.quote;
|
|
56
|
+
previewArgs = {
|
|
57
|
+
...args,
|
|
58
|
+
expected_addon_status: quote.current_addon_status,
|
|
59
|
+
expected_plan_code: quote.current_plan_code,
|
|
60
|
+
expected_price_usd: quote.price_usd,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return previewThenConfirm({
|
|
64
|
+
tool: 'manage_x_posting_addon',
|
|
65
|
+
action: 'buy',
|
|
66
|
+
args: previewArgs,
|
|
67
|
+
nonce: true,
|
|
68
|
+
legacyRefusal: 'Refusing to start an X posting add-on without confirm=true after the user agrees.',
|
|
69
|
+
ctx,
|
|
70
|
+
describe: async () => formatQuote(quote || {}),
|
|
71
|
+
run: async () => {
|
|
72
|
+
if (call.expected_addon_status === undefined || call.expected_plan_code === undefined || call.expected_price_usd === undefined) {
|
|
73
|
+
throw new Error('Confirm needs expected_addon_status, expected_plan_code, and expected_price_usd from the preview. Get a new preview.');
|
|
74
|
+
}
|
|
75
|
+
const result = await client.buyXPostingAddon({
|
|
76
|
+
confirm: true,
|
|
77
|
+
expected_addon_status: call.expected_addon_status,
|
|
78
|
+
expected_plan_code: call.expected_plan_code,
|
|
79
|
+
expected_price_usd: call.expected_price_usd,
|
|
80
|
+
...(call.plan_code ? { plan_code: call.plan_code } : {}),
|
|
81
|
+
...(call.workspace_id ? { workspace_id: call.workspace_id } : {}),
|
|
82
|
+
});
|
|
83
|
+
const url = typeof result.url === 'string' ? result.url : '';
|
|
84
|
+
return [
|
|
85
|
+
mdTitle(result.mode === 'portal' ? 'Billing page, nothing charged' : 'Checkout page, nothing charged yet'),
|
|
86
|
+
result.effect || 'Nothing was charged.',
|
|
87
|
+
url ? `Open this page to finish: ${url}` : 'No page was returned. Nothing was charged.',
|
|
88
|
+
].join('\n\n');
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
};
|