@flowapt/flowiq-cli 0.3.3 → 0.3.4

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 CHANGED
@@ -194,6 +194,15 @@ flowiq bc resume <org_id> --campaign july-referrals --commit [--retry-failed]
194
194
  `/api/send-template` as `headerMedia`, the same field the dashboard uses. A
195
195
  media-header template with no resolvable image is refused (pass
196
196
  `--header-media`).
197
+ - **`--python` engine (v0.3.4, `send --tag` only)**: hand the whole send to the
198
+ **python `/meta-broadcast` endpoint** — the *same* sender the dashboard's "Python
199
+ endpoint" toggle uses — via a staff-gated proxy (the master key stays server-side
200
+ in `VITE_PYTHON_RENDER_API_KEY`; the CLI never holds it). Python resolves the tag
201
+ + eligibility (`allow_broadcast=true`, not blocked; **no 2000-cap, paginated**) and
202
+ sends **fire-and-forget**, returning a `broadcastId`. Dry-run (no `--commit`) asks
203
+ python for the eligible count + a sample. Trade-off vs the default per-row engine:
204
+ no CLI write-ahead-log / `resume` (python owns the broadcast record), and archived
205
+ contacts aren't separately filtered. Media headers work on both engines.
197
206
  - **v1 scope**: Meta orgs, POSITIONAL templates, text / no header / media header.
198
207
  NAMED and carousel templates and WATI orgs are refused with a clear message.
199
208
  - **Validation before anything sends**: APPROVED-only, every slot mapped,
package/TEAM-GUIDE.md CHANGED
@@ -92,6 +92,7 @@ When you see it, run `npm i -g @flowapt/flowiq-cli` — a stale version also mea
92
92
  | Split a big id-list cohort into send-safe batch tags | `flowiq seg plan <org_id> --tag-prefix … --ids-file …` → `flowiq seg apply … --commit` |
93
93
  | Send to one batch tag | `flowiq bc send <org_id> --tag <batch-tag> --template … --body param1="Hi {{first_name}}" --commit` |
94
94
  | Send a broadcast whose template has an IMAGE header | Same as above — the image is automatic (the template's own header image). Override with `--header-media <public-image-url>` if needed. |
95
+ | Send via the SAME engine as the dashboard's "Python" toggle | add `--python` to a `bc send --tag …` (fire-and-forget; python resolves the tag + sends + tracks; no CLI resume for this engine) |
95
96
  | Read a contact's chat | `flowiq m pull <contact_id>` then open the JSON |
96
97
  | Export an org's full chat history | `flowiq export chats <org_id>` |
97
98
  | Check / create WhatsApp templates | `flowiq tpl pull <org_id>` / `flowiq tpl create <org_id> --request-file req.json` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowapt/flowiq-cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Command-line tool for FlowIQ staff: round-trip agent prompts, questionnaires, fine-tuning, pin-board tasks, webhooks, templates, agent-updates, chat exports, and live agent testing without ever touching service-role credentials.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -731,6 +731,54 @@ export function collectKV(pair, mapAcc) {
731
731
  return mapAcc;
732
732
  }
733
733
 
734
+ /** --python engine: hand the send to the python /meta-broadcast endpoint via the
735
+ * staff-gated proxy. Fire-and-forget — python resolves the tag + eligibility
736
+ * (allow_broadcast=true, not blocked) and sends in the background, returning a
737
+ * broadcastId. No CLI write-ahead log / resume for this engine (python owns the
738
+ * broadcast record). Dry-run (no --commit) asks python for the eligible count. */
739
+ async function runPythonTagSend(orgId, { opts, tag, templateName, template, headerMedia, bodyLiterals, buttonLiteral, commitStage }) {
740
+ const reqBody = (dryRun) => ({
741
+ action: "send-python", organization_id: orgId, tag, template_name: templateName,
742
+ body_parameters: bodyLiterals,
743
+ ...(buttonLiteral ? { button_parameters: { param1: buttonLiteral } } : {}),
744
+ ...(headerMedia ? { header_media: headerMedia } : {}),
745
+ dry_run: dryRun,
746
+ });
747
+
748
+ // Dry-run: python fetches the eligible contacts (no send) → count + sample.
749
+ let dry;
750
+ try { dry = await http.post("broadcast", reqBody(true)); }
751
+ catch (e) { console.error(`Python dry-run failed: ${e.message}`); if (e.body?.error) console.error(` ${e.body.error}`); process.exit(1); }
752
+ const total = dry.total_contacts_found ?? 0;
753
+
754
+ console.log("");
755
+ console.log(`Engine: PYTHON (yapi.store/meta-broadcast) — fire-and-forget, python-tracked.`);
756
+ console.log(`Tag "${tag}": ${total} eligible contact(s) (allow_broadcast + not blocked, resolved server-side).`);
757
+ const sampleNum = dry.sample_contacts?.[0]?.whatsapp_id || dry.sample_contacts?.[0]?.phone_number || "<first eligible>";
758
+ renderPreview(template, { rownum: 1, number: sampleNum, values: bodyLiterals, buttonValue: buttonLiteral }, headerMedia);
759
+ if (Object.values(bodyLiterals).some((v) => /\{\{(first_name|full_name|email|phone_number|whatsapp_id)\}\}/.test(String(v)))) {
760
+ console.log(" ({{first_name}}-style tokens are resolved PER CONTACT by python)");
761
+ }
762
+ console.log("");
763
+
764
+ if (!commitStage) {
765
+ console.log("DRY RUN — nothing sent. Add --commit to fire the python broadcast.");
766
+ return;
767
+ }
768
+ if (!total) { console.log("Nothing eligible under this tag."); return; }
769
+ if (!opts.yes) {
770
+ const answer = await ask(`Type the tag ("${tag}") to fire the python broadcast to ${total} contact(s): `);
771
+ if (answer !== tag) { console.log("Mismatch — aborted, nothing sent."); process.exit(0); }
772
+ }
773
+
774
+ let out;
775
+ try { out = await http.post("broadcast", reqBody(false)); }
776
+ catch (e) { console.error(`Python broadcast failed: ${e.message}`); if (e.body?.error) console.error(` ${e.body.error}`); process.exit(1); }
777
+ console.log("");
778
+ console.log(`✅ ${out.message || "Broadcast started"}${out.broadcastId ? ` · broadcastId ${out.broadcastId}` : ""}`);
779
+ console.log(` Python is sending in the background${out.mode ? ` (${out.mode})` : ""} and tracking it under that broadcast id — no CLI resume for this engine.`);
780
+ }
781
+
734
782
  async function runTagPipeline(orgId, opts, { commitStage }) {
735
783
  if (!UUID_RE.test(orgId)) { console.error(`Error: "${orgId}" is not a valid organization UUID.`); process.exit(1); }
736
784
  const campaign = opts.campaign || slugify(opts.tag, "tag-campaign");
@@ -764,6 +812,13 @@ async function runTagPipeline(orgId, opts, { commitStage }) {
764
812
  if (template.url_button?.present && !buttonLiteral) aborts.push("template has a dynamic URL button — pass --button param1=<code>");
765
813
  if (aborts.length) { for (const a of aborts) console.error(`ABORT — ${a}`); process.exit(1); }
766
814
 
815
+ // --python: hand the whole send to the python /meta-broadcast engine (the same
816
+ // sender the dashboard's "Python endpoint" toggle uses) via the staff-gated
817
+ // proxy. Python resolves the tag + eligibility + sends fire-and-forget.
818
+ if (opts.python) {
819
+ return runPythonTagSend(orgId, { opts, tag, templateName, template, headerMedia, bodyLiterals, buttonLiteral, commitStage });
820
+ }
821
+
767
822
  // resolve the tag server-side (broadcast-safe recipients only)
768
823
  let resolved;
769
824
  try { resolved = await http.post("broadcast", { action: "resolve-tag", organization_id: orgId, tag }); }
@@ -877,6 +932,7 @@ export async function preview(orgId, opts = {}) {
877
932
 
878
933
  export async function send(orgId, opts = {}) {
879
934
  if (opts.tag && opts.csv) { console.error("Error: --tag and --csv are mutually exclusive."); process.exit(1); }
935
+ if (opts.python && !opts.tag) { console.error("Error: --python requires --tag (the python engine is tag-based)."); process.exit(1); }
880
936
  if (opts.tag) return runTagPipeline(orgId, opts, { commitStage: !!opts.commit });
881
937
  await runPipeline(orgId, opts, { commitStage: !!opts.commit, isResume: !!opts.resume });
882
938
  }
package/src/index.js CHANGED
@@ -391,6 +391,7 @@ export function run(argv) {
391
391
  .option("--button <k=v>", "with --tag: dynamic URL button param, e.g. --button param1=<short-code>", broadcastCmd.collectKV, {})
392
392
  .option("--campaign <name>", "campaign id / config file slug (default: CSV filename / tag)")
393
393
  .option("--header-media <url>", "header image/video/doc URL for a media-header template (default: the template's own stored image)")
394
+ .option("--python", "with --tag: send via the python /meta-broadcast engine (same as the dashboard's Python toggle; fire-and-forget, python-tracked)")
394
395
  .option("--commit", "actually send (omit to dry-run)")
395
396
  .option("--yes", "skip the type-the-campaign-name confirm gate (CI)")
396
397
  .option("--force-remap", "ignore the saved mapping and rebuild interactively")