Skip to content

Commit 021f43e

Browse files
Merge pull request #104 from TopProjectsCreator/codex/fix-code-exporter-to-adhere-to-api-docs/2026-04-19
Fix automation exporter credential handling for Slack and Twilio
2 parents 4fe508e + f21ac79 commit 021f43e

1 file changed

Lines changed: 43 additions & 22 deletions

File tree

src/components/ide/AutomationTemplatePane.tsx

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,27 @@ export const AutomationTemplatePane = ({ initialBlocks, onBlocksChange, syncVers
683683
` response = sg.send(message)`,
684684
` return {"status_code": response.status_code}`,
685685
]},
686-
'Twilio': { pip: 'twilio', imports: ['from twilio.rest import Client as TwilioClient'], code: (cfg, ev) => [
687-
` client = TwilioClient(${ev}, TWILIO_AUTH_TOKEN)`,
688-
` body_text = prev.get("result", ${JSON.stringify(cfg.body || 'Hello from automation')}) if prev else ${JSON.stringify(cfg.body || 'Hello from automation')}`,
689-
` message = client.messages.create(body=body_text, from_="${cfg.from_number || '+1234567890'}", to="${cfg.to_number || '+0987654321'}")`,
690-
` return {"sid": message.sid}`,
686+
'Twilio': { pip: 'twilio', imports: ['from twilio.rest import Client as TwilioClient'], code: (cfg) => [
687+
` # Docs: https://www.twilio.com/docs/messaging/api/message-resource#create-a-message-resource`,
688+
` account_sid = os.getenv("TWILIO_ACCOUNT_SID")`,
689+
` auth_token = os.getenv("TWILIO_AUTH_TOKEN")`,
690+
` if not account_sid or not auth_token:`,
691+
` raise EnvironmentError("Twilio requires TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables.")`,
692+
` client = TwilioClient(account_sid, auth_token)`,
693+
` body_text = config.get("message") or (prev.get("result") if prev else None) or ${JSON.stringify(cfg.message || 'Hello from automation')}`,
694+
` message = client.messages.create(body=body_text, from_="${cfg.from || '+1234567890'}", to="${cfg.to || '+0987654321'}")`,
695+
` return {"sid": message.sid, "status": message.status}`,
691696
]},
692-
'Slack': { pip: 'slack-sdk', imports: ['from slack_sdk import WebClient'], code: (cfg, ev) => [
693-
` client = WebClient(token=${ev})`,
694-
` msg_text = prev.get("result", ${JSON.stringify(cfg.message || 'Hello from automation!')}) if prev else ${JSON.stringify(cfg.message || 'Hello from automation!')}`,
695-
` response = client.chat_postMessage(channel="${cfg.channel || '#general'}", text=msg_text)`,
696-
` return {"ts": response["ts"]}`,
697+
'Slack': { pip: 'requests', imports: [], code: (cfg) => [
698+
` # Docs: https://api.slack.com/messaging/webhooks`,
699+
` webhook_url = os.getenv("SLACK_WEBHOOK_URL")`,
700+
` if not webhook_url:`,
701+
` raise EnvironmentError("Slack webhook requires SLACK_WEBHOOK_URL environment variable.")`,
702+
` msg_text = config.get("message") or (prev.get("result") if prev else None) or ${JSON.stringify(cfg.message || 'Hello from automation!')}`,
703+
` payload = {"text": msg_text}`,
704+
` response = requests.post(webhook_url, json=payload)`,
705+
` response.raise_for_status()`,
706+
` return {"status": "ok", "status_code": response.status_code}`,
697707
]},
698708
'Discord': { pip: 'requests', imports: [], code: (cfg) => [
699709
` webhook_url = config.get("webhook_url", "")`,
@@ -908,7 +918,9 @@ export const AutomationTemplatePane = ({ initialBlocks, onBlocksChange, syncVers
908918
needsAuth.push({ label: b.label, envVar: ev, extraEnvVars: extras });
909919
}
910920
} else if (b.auth === 'api_key') {
911-
const ev = `${b.label.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_API_KEY`;
921+
let ev = `${b.label.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_API_KEY`;
922+
if (b.label === 'Slack') ev = 'SLACK_WEBHOOK_URL';
923+
if (b.label === 'Twilio') ev = 'TWILIO_ACCOUNT_SID';
912924
if (!needsAuth.find((a) => a.envVar === ev)) {
913925
const extras: string[] = [];
914926
if (b.label === 'Twilio') extras.push('TWILIO_AUTH_TOKEN');
@@ -1179,22 +1191,29 @@ export const AutomationTemplatePane = ({ initialBlocks, onBlocksChange, syncVers
11791191
` const { data } = await resend.emails.send({ from: "${cfg.from_email || 'you@yourdomain.com'}", to: ["${cfg.to_email || 'recipient@example.com'}"], subject: ${JSON.stringify(cfg.subject || 'Hello from automation')}, html: bodyHtml });`,
11801192
` return { email_id: data?.id };`,
11811193
]},
1182-
'Slack': { npm: '@slack/web-api', imports: ['const { WebClient } = require("@slack/web-api");'], code: (cfg, ev) => [
1183-
` const client = new WebClient(${ev});`,
1184-
` const msgText = prev?.result ?? ${JSON.stringify(cfg.message || 'Hello from automation!')};`,
1185-
` const response = await client.chat.postMessage({ channel: "${cfg.channel || '#general'}", text: msgText });`,
1186-
` return { ts: response.ts };`,
1194+
'Slack': { npm: 'node-fetch', imports: ['const fetch = require("node-fetch");'], code: (cfg) => [
1195+
` // Docs: https://api.slack.com/messaging/webhooks`,
1196+
` const webhookUrl = process.env.SLACK_WEBHOOK_URL;`,
1197+
` if (!webhookUrl) throw new Error("Slack webhook requires SLACK_WEBHOOK_URL environment variable.");`,
1198+
` const msgText = config.message || prev?.result || ${JSON.stringify(cfg.message || 'Hello from automation!')};`,
1199+
` const response = await fetch(webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: msgText }) });`,
1200+
` if (!response.ok) throw new Error(\`Slack webhook failed: \${response.status}\`);`,
1201+
` return { status: "ok", statusCode: response.status };`,
11871202
]},
11881203
'Stripe': { npm: 'stripe', imports: ['const Stripe = require("stripe");'], code: (cfg, ev) => [
11891204
` const stripe = new Stripe(${ev});`,
11901205
` const intent = await stripe.paymentIntents.create({ amount: ${cfg.amount || '1000'}, currency: "${cfg.currency || 'usd'}" });`,
11911206
` return { client_secret: intent.client_secret };`,
11921207
]},
1193-
'Twilio': { npm: 'twilio', imports: ['const twilio = require("twilio");'], code: (cfg, ev) => [
1194-
` const client = twilio(${ev}, process.env.TWILIO_AUTH_TOKEN);`,
1195-
` const bodyText = prev?.result ?? ${JSON.stringify(cfg.body || 'Hello from automation')};`,
1196-
` const message = await client.messages.create({ body: bodyText, from: "${cfg.from_number || '+1234567890'}", to: "${cfg.to_number || '+0987654321'}" });`,
1197-
` return { sid: message.sid };`,
1208+
'Twilio': { npm: 'twilio', imports: ['const twilio = require("twilio");'], code: (cfg) => [
1209+
` // Docs: https://www.twilio.com/docs/messaging/api/message-resource#create-a-message-resource`,
1210+
` const accountSid = process.env.TWILIO_ACCOUNT_SID;`,
1211+
` const authToken = process.env.TWILIO_AUTH_TOKEN;`,
1212+
` if (!accountSid || !authToken) throw new Error("Twilio requires TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN.");`,
1213+
` const client = twilio(accountSid, authToken);`,
1214+
` const bodyText = config.message || prev?.result || ${JSON.stringify(cfg.message || 'Hello from automation')};`,
1215+
` const message = await client.messages.create({ body: bodyText, from: "${cfg.from || '+1234567890'}", to: "${cfg.to || '+0987654321'}" });`,
1216+
` return { sid: message.sid, status: message.status };`,
11981217
]},
11991218
'GitHub': { npm: 'node-fetch', imports: ['const fetch = require("node-fetch");'], code: (cfg, ev) => [
12001219
` const res = await fetch(\`https://api.github.com/repos/${cfg.owner || 'owner'}/${cfg.repo || 'repo'}\`, { headers: { Authorization: \`Bearer \${${ev}}\`, Accept: "application/vnd.github+json" } });`,
@@ -1287,7 +1306,9 @@ export const AutomationTemplatePane = ({ initialBlocks, onBlocksChange, syncVers
12871306
}
12881307
if (sdkHint) npmPackages.add(sdkHint);
12891308
if (b.auth === 'api_key') {
1290-
const ev = `${b.label.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_API_KEY`;
1309+
let ev = `${b.label.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_API_KEY`;
1310+
if (b.label === 'Slack') ev = 'SLACK_WEBHOOK_URL';
1311+
if (b.label === 'Twilio') ev = 'TWILIO_ACCOUNT_SID';
12911312
if (!needsAuth.find((a) => a.envVar === ev)) {
12921313
const extras: string[] = [];
12931314
if (b.label === 'Twilio') extras.push('TWILIO_AUTH_TOKEN');

0 commit comments

Comments
 (0)