@opally/cli 0.1.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/LICENSE +21 -0
- package/SKILL.md +118 -0
- package/dist/bin/opally.d.ts +2 -0
- package/dist/bin/opally.js +22 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +57 -0
- package/dist/commands/analytics.d.ts +2 -0
- package/dist/commands/analytics.js +95 -0
- package/dist/commands/chats.d.ts +2 -0
- package/dist/commands/chats.js +86 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +52 -0
- package/dist/commands/emails.d.ts +2 -0
- package/dist/commands/emails.js +61 -0
- package/dist/commands/leads.d.ts +2 -0
- package/dist/commands/leads.js +44 -0
- package/dist/commands/voice.d.ts +2 -0
- package/dist/commands/voice.js +54 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +44 -0
- package/dist/output.d.ts +3 -0
- package/dist/output.js +40 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Opally
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Opally
|
|
2
|
+
|
|
3
|
+
AI-powered receptionist platform for the hospitality industry. Query guest conversations, email activity, voice calls, leads, and analytics.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Install the CLI and configure your API key:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @opally/cli
|
|
11
|
+
opally config set-key op_live_YOUR_KEY_HERE
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or set via environment variable:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
export OPALLY_API_KEY=op_live_YOUR_KEY_HERE
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Tools
|
|
21
|
+
|
|
22
|
+
### leads list
|
|
23
|
+
List guest leads from chat, voice, and messaging channels.
|
|
24
|
+
```bash
|
|
25
|
+
opally leads list [--from <date>] [--to <date>] [--source <chat|voice|whatsapp|messenger|instagram>] [--limit <n>] [--json]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### leads get
|
|
29
|
+
Get detailed information about a specific lead including their conversation.
|
|
30
|
+
```bash
|
|
31
|
+
opally leads get <id> [--json]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### emails list
|
|
35
|
+
List email logs showing processed emails and AI-generated drafts.
|
|
36
|
+
```bash
|
|
37
|
+
opally emails list [--from <date>] [--to <date>] [--status <processed|draft_created|filtered|spam_filtered|paired|deduplicated>] [--limit <n>] [--json]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### emails get
|
|
41
|
+
Get email details including the decrypted AI draft and send status.
|
|
42
|
+
```bash
|
|
43
|
+
opally emails get <id> [--json]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### chats list
|
|
47
|
+
List chat conversations across all messaging platforms.
|
|
48
|
+
```bash
|
|
49
|
+
opally chats list [--from <date>] [--to <date>] [--platform <webchat|whatsapp|messenger|instagram>] [--limit <n>] [--json]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### chats get
|
|
53
|
+
Get chat conversation details including message count and guest email.
|
|
54
|
+
```bash
|
|
55
|
+
opally chats get <id> [--json]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### chats messages
|
|
59
|
+
Read the full message history of a chat conversation.
|
|
60
|
+
```bash
|
|
61
|
+
opally chats messages <id> [--json]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### voice list
|
|
65
|
+
List voice call logs.
|
|
66
|
+
```bash
|
|
67
|
+
opally voice list [--from <date>] [--to <date>] [--limit <n>] [--json]
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### voice get
|
|
71
|
+
Get detailed voice call information.
|
|
72
|
+
```bash
|
|
73
|
+
opally voice get <id> [--json]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### analytics overview
|
|
77
|
+
Get a high-level summary of all activity (emails, chats, voice, leads, agent actions).
|
|
78
|
+
```bash
|
|
79
|
+
opally analytics overview [--from <date>] [--to <date>] [--json]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### analytics emails
|
|
83
|
+
Time-series email processing metrics.
|
|
84
|
+
```bash
|
|
85
|
+
opally analytics emails [--from <date>] [--to <date>] [--interval <day|week|month>] [--status <status>] [--json]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### analytics chats
|
|
89
|
+
Time-series chat activity metrics.
|
|
90
|
+
```bash
|
|
91
|
+
opally analytics chats [--from <date>] [--to <date>] [--interval <day|week|month>] [--platform <platform>] [--json]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### analytics voice
|
|
95
|
+
Time-series voice call metrics.
|
|
96
|
+
```bash
|
|
97
|
+
opally analytics voice [--from <date>] [--to <date>] [--interval <day|week|month>] [--json]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### analytics leads
|
|
101
|
+
Time-series lead generation metrics.
|
|
102
|
+
```bash
|
|
103
|
+
opally analytics leads [--from <date>] [--to <date>] [--interval <day|week|month>] [--source <source>] [--json]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### analytics agent-actions
|
|
107
|
+
Time-series metrics for autonomous agent actions (bookings, modifications, etc).
|
|
108
|
+
```bash
|
|
109
|
+
opally analytics agent-actions [--from <date>] [--to <date>] [--interval <day|week|month>] [--action-type <type>] [--status <status>] [--initiator <channel>] [--json]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Notes
|
|
113
|
+
|
|
114
|
+
- All dates are ISO 8601 format (e.g., `2026-03-01`)
|
|
115
|
+
- Date ranges are capped at 90 days
|
|
116
|
+
- Use `--json` for machine-readable output (recommended for automated workflows)
|
|
117
|
+
- Pagination: use `--cursor` with the cursor returned from list commands
|
|
118
|
+
- Default limit is 25 results, max 100
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const config_js_1 = require("../commands/config.js");
|
|
6
|
+
const leads_js_1 = require("../commands/leads.js");
|
|
7
|
+
const emails_js_1 = require("../commands/emails.js");
|
|
8
|
+
const chats_js_1 = require("../commands/chats.js");
|
|
9
|
+
const voice_js_1 = require("../commands/voice.js");
|
|
10
|
+
const analytics_js_1 = require("../commands/analytics.js");
|
|
11
|
+
const program = new commander_1.Command();
|
|
12
|
+
program
|
|
13
|
+
.name("opally")
|
|
14
|
+
.description("CLI for the Opally API")
|
|
15
|
+
.version("0.1.0");
|
|
16
|
+
program.addCommand(config_js_1.configCommand);
|
|
17
|
+
program.addCommand(leads_js_1.leadsCommand);
|
|
18
|
+
program.addCommand(emails_js_1.emailsCommand);
|
|
19
|
+
program.addCommand(chats_js_1.chatsCommand);
|
|
20
|
+
program.addCommand(voice_js_1.voiceCommand);
|
|
21
|
+
program.addCommand(analytics_js_1.analyticsCommand);
|
|
22
|
+
program.parse();
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function validateId(id: string): string;
|
|
2
|
+
export interface PaginatedResponse<T> {
|
|
3
|
+
data: T[];
|
|
4
|
+
pagination: {
|
|
5
|
+
has_more: boolean;
|
|
6
|
+
next_cursor: string | null;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface SingleResponse<T> {
|
|
10
|
+
data: T;
|
|
11
|
+
}
|
|
12
|
+
export interface ApiError {
|
|
13
|
+
error: string;
|
|
14
|
+
details?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function api<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateId = validateId;
|
|
4
|
+
exports.api = api;
|
|
5
|
+
const config_js_1 = require("./config.js");
|
|
6
|
+
const ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
7
|
+
function validateId(id) {
|
|
8
|
+
if (!ID_PATTERN.test(id)) {
|
|
9
|
+
console.error("Invalid ID format. IDs must be alphanumeric (with - and _ allowed).");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
return id;
|
|
13
|
+
}
|
|
14
|
+
async function api(path, params) {
|
|
15
|
+
const baseUrl = (0, config_js_1.getBaseUrl)();
|
|
16
|
+
const url = new URL(`/api/v1${path}`, baseUrl);
|
|
17
|
+
if (params) {
|
|
18
|
+
for (const [key, value] of Object.entries(params)) {
|
|
19
|
+
if (value !== undefined) {
|
|
20
|
+
url.searchParams.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const res = await fetch(url.toString(), {
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${(0, config_js_1.getApiKey)()}`,
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const text = await res.text();
|
|
31
|
+
let body = null;
|
|
32
|
+
try {
|
|
33
|
+
body = JSON.parse(text);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Response is not JSON
|
|
37
|
+
}
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
if (body && typeof body === "object" && "error" in body) {
|
|
40
|
+
const err = body;
|
|
41
|
+
console.error(`Error ${res.status}: ${err.error}`);
|
|
42
|
+
if (err.details)
|
|
43
|
+
console.error(`Details: ${err.details}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error(`Error ${res.status}: ${res.statusText || "Request failed"}`);
|
|
47
|
+
if (text)
|
|
48
|
+
console.error("Response:", text.slice(0, 500));
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
if (body === null) {
|
|
53
|
+
console.error("Error: Expected JSON response but received non-JSON body");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
return body;
|
|
57
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyticsCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const output_js_1 = require("../output.js");
|
|
7
|
+
exports.analyticsCommand = new commander_1.Command("analytics")
|
|
8
|
+
.description("View analytics and metrics");
|
|
9
|
+
exports.analyticsCommand
|
|
10
|
+
.command("overview")
|
|
11
|
+
.description("High-level summary of all activity")
|
|
12
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
13
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
14
|
+
.option("--json", "Output as JSON")
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
const res = await (0, client_js_1.api)("/analytics/overview", {
|
|
17
|
+
from: opts.from,
|
|
18
|
+
to: opts.to,
|
|
19
|
+
});
|
|
20
|
+
if (opts.json) {
|
|
21
|
+
(0, output_js_1.output)(res, "json");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const { period, ...metrics } = res;
|
|
25
|
+
console.log(`Period: ${period.from} → ${period.to}\n`);
|
|
26
|
+
for (const [section, data] of Object.entries(metrics)) {
|
|
27
|
+
console.log(`${section.toUpperCase()}:`);
|
|
28
|
+
if (typeof data === "object" && data !== null) {
|
|
29
|
+
for (const [key, val] of Object.entries(data)) {
|
|
30
|
+
if (typeof val === "object" && val !== null) {
|
|
31
|
+
console.log(` ${key}:`);
|
|
32
|
+
for (const [k, v] of Object.entries(val)) {
|
|
33
|
+
console.log(` ${k}: ${v}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log(` ${key}: ${val}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(` ${data}`);
|
|
43
|
+
}
|
|
44
|
+
console.log();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
function addTimeSeriesCommand(name, path, description, extraFilters) {
|
|
48
|
+
const cmd = exports.analyticsCommand
|
|
49
|
+
.command(name)
|
|
50
|
+
.description(description)
|
|
51
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
52
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
53
|
+
.option("--interval <interval>", "Granularity: day, week, month", "day")
|
|
54
|
+
.option("--json", "Output as JSON");
|
|
55
|
+
if (extraFilters) {
|
|
56
|
+
for (const f of extraFilters) {
|
|
57
|
+
cmd.option(`--${f.name} <value>`, f.desc);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
cmd.action(async (opts) => {
|
|
61
|
+
const params = {
|
|
62
|
+
from: opts.from,
|
|
63
|
+
to: opts.to,
|
|
64
|
+
interval: opts.interval,
|
|
65
|
+
};
|
|
66
|
+
if (extraFilters) {
|
|
67
|
+
for (const f of extraFilters) {
|
|
68
|
+
const camel = f.name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
69
|
+
params[f.name.replace(/-/g, "_")] = opts[camel];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const res = await (0, client_js_1.api)(path, params);
|
|
73
|
+
if (opts.json) {
|
|
74
|
+
(0, output_js_1.output)(res, "json");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log(`Period: ${res.period.from} → ${res.period.to} (${res.interval})\n`);
|
|
78
|
+
(0, output_js_1.output)(res.data, "table");
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
addTimeSeriesCommand("emails", "/analytics/emails", "Email analytics over time", [
|
|
82
|
+
{ name: "status", desc: "Filter: processed, draft_created, filtered, spam_filtered, paired, deduplicated" },
|
|
83
|
+
]);
|
|
84
|
+
addTimeSeriesCommand("chats", "/analytics/chats", "Chat analytics over time", [
|
|
85
|
+
{ name: "platform", desc: "Filter: webchat, whatsapp, messenger, instagram" },
|
|
86
|
+
]);
|
|
87
|
+
addTimeSeriesCommand("voice", "/analytics/voice", "Voice analytics over time");
|
|
88
|
+
addTimeSeriesCommand("leads", "/analytics/leads", "Lead analytics over time", [
|
|
89
|
+
{ name: "source", desc: "Filter: chat, voice, whatsapp, messenger, instagram" },
|
|
90
|
+
]);
|
|
91
|
+
addTimeSeriesCommand("agent-actions", "/analytics/agent-actions", "Agent action analytics over time", [
|
|
92
|
+
{ name: "action-type", desc: "Filter: booking_modification, booking_cancellation, date_change, room_upgrade, add_service, special_request, general_inquiry, response_generation, tool_execution" },
|
|
93
|
+
{ name: "status", desc: "Filter: pending_approval, auto_executed, manually_approved, rejected, failed, cancelled" },
|
|
94
|
+
{ name: "initiator", desc: "Filter: email, chat, voice, whatsapp, messenger, instagram" },
|
|
95
|
+
]);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chatsCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const output_js_1 = require("../output.js");
|
|
7
|
+
exports.chatsCommand = new commander_1.Command("chats")
|
|
8
|
+
.description("View chat conversations");
|
|
9
|
+
exports.chatsCommand
|
|
10
|
+
.command("list")
|
|
11
|
+
.description("List chat conversations")
|
|
12
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
13
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
14
|
+
.option("--platform <platform>", "Filter: webchat, whatsapp, messenger, instagram")
|
|
15
|
+
.option("--limit <n>", "Results per page (1-100)")
|
|
16
|
+
.option("--cursor <cursor>", "Pagination cursor")
|
|
17
|
+
.option("--json", "Output as JSON")
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
const res = await (0, client_js_1.api)("/conversations/chats", {
|
|
20
|
+
from: opts.from,
|
|
21
|
+
to: opts.to,
|
|
22
|
+
platform: opts.platform,
|
|
23
|
+
limit: opts.limit,
|
|
24
|
+
cursor: opts.cursor,
|
|
25
|
+
});
|
|
26
|
+
(0, output_js_1.output)(res.data, opts.json ? "json" : "table", [
|
|
27
|
+
"id",
|
|
28
|
+
"title",
|
|
29
|
+
"platform",
|
|
30
|
+
"language",
|
|
31
|
+
"created_at",
|
|
32
|
+
]);
|
|
33
|
+
if (res.pagination.has_more) {
|
|
34
|
+
console.log(`\nMore results available. Use --cursor ${res.pagination.next_cursor}`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.chatsCommand
|
|
38
|
+
.command("get <id>")
|
|
39
|
+
.description("Get chat conversation details")
|
|
40
|
+
.option("--json", "Output as JSON")
|
|
41
|
+
.action(async (id, opts) => {
|
|
42
|
+
const res = await (0, client_js_1.api)(`/conversations/chats/${(0, client_js_1.validateId)(id)}`);
|
|
43
|
+
const data = res.data;
|
|
44
|
+
if (opts.json) {
|
|
45
|
+
(0, output_js_1.output)(data, "json");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(`Title: ${data.title}`);
|
|
49
|
+
console.log(`Platform: ${data.platform}`);
|
|
50
|
+
console.log(`Language: ${data.language}`);
|
|
51
|
+
console.log(`Guest: ${data.guest_email || "(unknown)"}`);
|
|
52
|
+
console.log(`Messages: ${data.message_count}`);
|
|
53
|
+
console.log(`Created: ${data.created_at}`);
|
|
54
|
+
});
|
|
55
|
+
exports.chatsCommand
|
|
56
|
+
.command("messages <id>")
|
|
57
|
+
.description("Get messages in a chat conversation")
|
|
58
|
+
.option("--json", "Output as JSON")
|
|
59
|
+
.action(async (id, opts) => {
|
|
60
|
+
const res = await (0, client_js_1.api)(`/conversations/chats/${(0, client_js_1.validateId)(id)}/messages`);
|
|
61
|
+
const messages = res.data.messages;
|
|
62
|
+
if (opts.json) {
|
|
63
|
+
(0, output_js_1.output)(messages, "json");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const msg of messages) {
|
|
67
|
+
const role = msg.role === "assistant" ? "Opally" : "Guest";
|
|
68
|
+
const time = new Date(msg.created_at).toLocaleString();
|
|
69
|
+
// Message content may be JSON-encoded chat parts
|
|
70
|
+
let text = msg.content;
|
|
71
|
+
try {
|
|
72
|
+
const parts = JSON.parse(msg.content);
|
|
73
|
+
if (Array.isArray(parts)) {
|
|
74
|
+
text = parts
|
|
75
|
+
.flatMap((p) => (p.parts || []).filter((pt) => pt.type === "text").map((pt) => pt.text))
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.join("\n") || text;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Plain text content, use as-is
|
|
82
|
+
}
|
|
83
|
+
console.log(`[${time}] ${role}:`);
|
|
84
|
+
console.log(` ${text}\n`);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
exports.configCommand = new commander_1.Command("config")
|
|
7
|
+
.description("Manage CLI configuration");
|
|
8
|
+
exports.configCommand
|
|
9
|
+
.command("set-key <key>")
|
|
10
|
+
.description("Save your Opally API key")
|
|
11
|
+
.action((key) => {
|
|
12
|
+
if (!key.startsWith("op_live_") && !key.startsWith("op_test_")) {
|
|
13
|
+
console.error("Invalid key format. Expected op_live_* or op_test_*");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
if (key.length < 32) {
|
|
17
|
+
console.error("Invalid key format. Key is too short.");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const config = (0, config_js_1.loadConfig)();
|
|
21
|
+
config.api_key = key;
|
|
22
|
+
(0, config_js_1.saveConfig)(config);
|
|
23
|
+
console.log("API key saved to ~/.opally/config.json");
|
|
24
|
+
});
|
|
25
|
+
exports.configCommand
|
|
26
|
+
.command("set-url <url>")
|
|
27
|
+
.description("Set the Opally API base URL")
|
|
28
|
+
.action((url) => {
|
|
29
|
+
try {
|
|
30
|
+
const parsed = new URL(url);
|
|
31
|
+
if (parsed.protocol !== "https:") {
|
|
32
|
+
console.error("Base URL must use HTTPS.");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
console.error("Invalid URL format.");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const config = (0, config_js_1.loadConfig)();
|
|
41
|
+
config.base_url = url;
|
|
42
|
+
(0, config_js_1.saveConfig)(config);
|
|
43
|
+
console.log(`Base URL set to ${url}`);
|
|
44
|
+
});
|
|
45
|
+
exports.configCommand
|
|
46
|
+
.command("show")
|
|
47
|
+
.description("Show current configuration")
|
|
48
|
+
.action(() => {
|
|
49
|
+
const config = (0, config_js_1.loadConfig)();
|
|
50
|
+
console.log(`API key: ${config.api_key ? config.api_key.slice(0, 12) + "..." : "(not set)"}`);
|
|
51
|
+
console.log(`Base URL: ${config.base_url || "https://api.opally.com (default)"}`);
|
|
52
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emailsCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const output_js_1 = require("../output.js");
|
|
7
|
+
exports.emailsCommand = new commander_1.Command("emails")
|
|
8
|
+
.description("View email conversations");
|
|
9
|
+
exports.emailsCommand
|
|
10
|
+
.command("list")
|
|
11
|
+
.description("List email logs")
|
|
12
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
13
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
14
|
+
.option("--status <status>", "Filter: processed, draft_created, filtered, spam_filtered, paired, deduplicated")
|
|
15
|
+
.option("--limit <n>", "Results per page (1-100)")
|
|
16
|
+
.option("--cursor <cursor>", "Pagination cursor")
|
|
17
|
+
.option("--json", "Output as JSON")
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
const res = await (0, client_js_1.api)("/conversations/emails", {
|
|
20
|
+
from: opts.from,
|
|
21
|
+
to: opts.to,
|
|
22
|
+
status: opts.status,
|
|
23
|
+
limit: opts.limit,
|
|
24
|
+
cursor: opts.cursor,
|
|
25
|
+
});
|
|
26
|
+
(0, output_js_1.output)(res.data, opts.json ? "json" : "table", [
|
|
27
|
+
"id",
|
|
28
|
+
"subject",
|
|
29
|
+
"sender",
|
|
30
|
+
"status",
|
|
31
|
+
"timestamp",
|
|
32
|
+
]);
|
|
33
|
+
if (res.pagination.has_more) {
|
|
34
|
+
console.log(`\nMore results available. Use --cursor ${res.pagination.next_cursor}`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.emailsCommand
|
|
38
|
+
.command("get <id>")
|
|
39
|
+
.description("Get email details with draft")
|
|
40
|
+
.option("--json", "Output as JSON")
|
|
41
|
+
.action(async (id, opts) => {
|
|
42
|
+
const res = await (0, client_js_1.api)(`/conversations/emails/${(0, client_js_1.validateId)(id)}`);
|
|
43
|
+
const data = res.data;
|
|
44
|
+
if (opts.json) {
|
|
45
|
+
(0, output_js_1.output)(data, "json");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(`Subject: ${data.subject}`);
|
|
49
|
+
console.log(`Sender: ${data.sender}`);
|
|
50
|
+
console.log(`Status: ${data.status}`);
|
|
51
|
+
console.log(`Time: ${data.timestamp}`);
|
|
52
|
+
if (data.draft) {
|
|
53
|
+
console.log(`\n--- Draft ---`);
|
|
54
|
+
console.log(`Subject: ${data.draft.subject}`);
|
|
55
|
+
console.log(`Status: ${data.draft.status}`);
|
|
56
|
+
console.log(`Created: ${data.draft.draft_created_at}`);
|
|
57
|
+
if (data.draft.sent_at)
|
|
58
|
+
console.log(`Sent: ${data.draft.sent_at}`);
|
|
59
|
+
console.log(`\n${data.draft.body}`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.leadsCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const output_js_1 = require("../output.js");
|
|
7
|
+
exports.leadsCommand = new commander_1.Command("leads")
|
|
8
|
+
.description("Manage chat leads");
|
|
9
|
+
exports.leadsCommand
|
|
10
|
+
.command("list")
|
|
11
|
+
.description("List leads")
|
|
12
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
13
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
14
|
+
.option("--source <source>", "Filter: chat, voice, whatsapp, messenger, instagram")
|
|
15
|
+
.option("--limit <n>", "Results per page (1-100)")
|
|
16
|
+
.option("--cursor <cursor>", "Pagination cursor")
|
|
17
|
+
.option("--json", "Output as JSON")
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
const res = await (0, client_js_1.api)("/leads", {
|
|
20
|
+
from: opts.from,
|
|
21
|
+
to: opts.to,
|
|
22
|
+
source: opts.source,
|
|
23
|
+
limit: opts.limit,
|
|
24
|
+
cursor: opts.cursor,
|
|
25
|
+
});
|
|
26
|
+
(0, output_js_1.output)(res.data, opts.json ? "json" : "table", [
|
|
27
|
+
"id",
|
|
28
|
+
"name",
|
|
29
|
+
"email",
|
|
30
|
+
"source",
|
|
31
|
+
"created_at",
|
|
32
|
+
]);
|
|
33
|
+
if (res.pagination.has_more) {
|
|
34
|
+
console.log(`\nMore results available. Use --cursor ${res.pagination.next_cursor}`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.leadsCommand
|
|
38
|
+
.command("get <id>")
|
|
39
|
+
.description("Get lead details")
|
|
40
|
+
.option("--json", "Output as JSON")
|
|
41
|
+
.action(async (id, opts) => {
|
|
42
|
+
const res = await (0, client_js_1.api)(`/leads/${(0, client_js_1.validateId)(id)}`);
|
|
43
|
+
(0, output_js_1.output)(res.data, opts.json ? "json" : "table");
|
|
44
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.voiceCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const client_js_1 = require("../client.js");
|
|
6
|
+
const output_js_1 = require("../output.js");
|
|
7
|
+
exports.voiceCommand = new commander_1.Command("voice")
|
|
8
|
+
.description("View voice call logs");
|
|
9
|
+
exports.voiceCommand
|
|
10
|
+
.command("list")
|
|
11
|
+
.description("List voice calls")
|
|
12
|
+
.option("--from <date>", "Start date (ISO 8601)")
|
|
13
|
+
.option("--to <date>", "End date (ISO 8601)")
|
|
14
|
+
.option("--limit <n>", "Results per page (1-100)")
|
|
15
|
+
.option("--cursor <cursor>", "Pagination cursor")
|
|
16
|
+
.option("--json", "Output as JSON")
|
|
17
|
+
.action(async (opts) => {
|
|
18
|
+
const res = await (0, client_js_1.api)("/conversations/voice", {
|
|
19
|
+
from: opts.from,
|
|
20
|
+
to: opts.to,
|
|
21
|
+
limit: opts.limit,
|
|
22
|
+
cursor: opts.cursor,
|
|
23
|
+
});
|
|
24
|
+
(0, output_js_1.output)(res.data, opts.json ? "json" : "table", [
|
|
25
|
+
"id",
|
|
26
|
+
"from_number",
|
|
27
|
+
"to_number",
|
|
28
|
+
"duration_seconds",
|
|
29
|
+
"status",
|
|
30
|
+
"started_at",
|
|
31
|
+
]);
|
|
32
|
+
if (res.pagination.has_more) {
|
|
33
|
+
console.log(`\nMore results available. Use --cursor ${res.pagination.next_cursor}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.voiceCommand
|
|
37
|
+
.command("get <id>")
|
|
38
|
+
.description("Get voice call details")
|
|
39
|
+
.option("--json", "Output as JSON")
|
|
40
|
+
.action(async (id, opts) => {
|
|
41
|
+
const res = await (0, client_js_1.api)(`/conversations/voice/${(0, client_js_1.validateId)(id)}`);
|
|
42
|
+
const data = res.data;
|
|
43
|
+
if (opts.json) {
|
|
44
|
+
(0, output_js_1.output)(data, "json");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.log(`From: ${data.from_number}`);
|
|
48
|
+
console.log(`To: ${data.to_number}`);
|
|
49
|
+
console.log(`Status: ${data.status}`);
|
|
50
|
+
console.log(`Started: ${data.started_at}`);
|
|
51
|
+
if (data.ended_at)
|
|
52
|
+
console.log(`Ended: ${data.ended_at}`);
|
|
53
|
+
console.log(`Duration: ${data.duration_seconds}s`);
|
|
54
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
api_key?: string;
|
|
3
|
+
base_url?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function loadConfig(): Config;
|
|
6
|
+
export declare function saveConfig(config: Config): void;
|
|
7
|
+
export declare function getApiKey(): string;
|
|
8
|
+
export declare function getBaseUrl(): string;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfig = loadConfig;
|
|
4
|
+
exports.saveConfig = saveConfig;
|
|
5
|
+
exports.getApiKey = getApiKey;
|
|
6
|
+
exports.getBaseUrl = getBaseUrl;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const os_1 = require("os");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const CONFIG_DIR = (0, path_1.join)((0, os_1.homedir)(), ".opally");
|
|
11
|
+
const CONFIG_FILE = (0, path_1.join)(CONFIG_DIR, "config.json");
|
|
12
|
+
function loadConfig() {
|
|
13
|
+
if (!(0, fs_1.existsSync)(CONFIG_FILE))
|
|
14
|
+
return {};
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse((0, fs_1.readFileSync)(CONFIG_FILE, "utf-8"));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function saveConfig(config) {
|
|
23
|
+
if (!(0, fs_1.existsSync)(CONFIG_DIR)) {
|
|
24
|
+
(0, fs_1.mkdirSync)(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
25
|
+
}
|
|
26
|
+
(0, fs_1.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2) + "\n", {
|
|
27
|
+
mode: 0o600,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function getApiKey() {
|
|
31
|
+
const envKey = process.env.OPALLY_API_KEY;
|
|
32
|
+
if (envKey)
|
|
33
|
+
return envKey;
|
|
34
|
+
const config = loadConfig();
|
|
35
|
+
if (config.api_key)
|
|
36
|
+
return config.api_key;
|
|
37
|
+
console.error("No API key found. Set OPALLY_API_KEY or run: opally config set-key <key>");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
function getBaseUrl() {
|
|
41
|
+
return (process.env.OPALLY_BASE_URL ||
|
|
42
|
+
loadConfig().base_url ||
|
|
43
|
+
"https://api.opally.com");
|
|
44
|
+
}
|
package/dist/output.d.ts
ADDED
package/dist/output.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.table = table;
|
|
4
|
+
exports.json = json;
|
|
5
|
+
exports.output = output;
|
|
6
|
+
function table(rows, columns) {
|
|
7
|
+
if (rows.length === 0) {
|
|
8
|
+
console.log("No results.");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const cols = columns || Object.keys(rows[0]);
|
|
12
|
+
// Calculate column widths
|
|
13
|
+
const widths = cols.map((col) => Math.max(col.length, ...rows.map((row) => String(row[col] ?? "").length)));
|
|
14
|
+
// Header
|
|
15
|
+
const header = cols.map((col, i) => col.padEnd(widths[i])).join(" ");
|
|
16
|
+
const separator = widths.map((w) => "─".repeat(w)).join("──");
|
|
17
|
+
console.log(header);
|
|
18
|
+
console.log(separator);
|
|
19
|
+
// Rows
|
|
20
|
+
for (const row of rows) {
|
|
21
|
+
const line = cols
|
|
22
|
+
.map((col, i) => String(row[col] ?? "").padEnd(widths[i]))
|
|
23
|
+
.join(" ");
|
|
24
|
+
console.log(line);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function json(data) {
|
|
28
|
+
console.log(JSON.stringify(data, null, 2));
|
|
29
|
+
}
|
|
30
|
+
function output(data, format, columns) {
|
|
31
|
+
if (format === "json") {
|
|
32
|
+
json(data);
|
|
33
|
+
}
|
|
34
|
+
else if (Array.isArray(data)) {
|
|
35
|
+
table(data, columns);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
json(data);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opally/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for the Opally API — query guest conversations, emails, voice calls, leads, and analytics.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"opally": "./dist/bin/opally.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"SKILL.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsx src/bin/opally.ts",
|
|
15
|
+
"start": "node dist/bin/opally.js",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"opally",
|
|
20
|
+
"hospitality",
|
|
21
|
+
"hotel",
|
|
22
|
+
"cli",
|
|
23
|
+
"api"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/opally-com/opally-cli.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/opally-com/opally-cli#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/opally-com/opally-cli/issues"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^12.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsx": "^4.19.0",
|
|
38
|
+
"typescript": "^5.5.0",
|
|
39
|
+
"@types/node": "^22.0.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT"
|
|
45
|
+
}
|