Files
html/api/blade-tasks/resend-click-template.json
opus c19bdff221
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync via WEVIA git_sync_all intent 2026-04-20T02:48:39+02:00
2026-04-20 02:48:39 +02:00

12 lines
14 KiB
JSON

{
"id": "TEMPLATE",
"name": "Resend Add API Key via Chrome Selenium",
"type": "powershell",
"priority": "high",
"command": "\n# WEVIA via Blade Chrome \u2014 Resend Add API Key automation\n$ErrorActionPreference = \"Continue\"\n$startTime = Get-Date\nWrite-Host \"[BLADE] Resend API Key automation START $startTime\"\n\n# Install Selenium if missing\nif (!(Get-Module -ListAvailable -Name Selenium)) {\n Install-Module Selenium -Force -Scope CurrentUser -AllowClobber -ErrorAction SilentlyContinue\n}\n\ntry {\n Import-Module Selenium -ErrorAction Stop\n \n # Use existing Chrome profile (user already logged into Resend)\n $chromeProfile = \"$env:LOCALAPPDATA\\Google\\Chrome\\User Data\"\n \n $options = New-Object OpenQA.Selenium.Chrome.ChromeOptions\n $options.AddArgument(\"--no-sandbox\")\n $options.AddArgument(\"--disable-blink-features=AutomationControlled\")\n # NOTE: we attach to Balei profile to keep the Resend session cookie\n # $options.AddArgument(\"--user-data-dir=$chromeProfile\")\n # $options.AddArgument(\"--profile-directory=Default\")\n \n $driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)\n Write-Host \"[BLADE] Chrome started\"\n \n # Go to Resend onboarding\n $driver.Navigate().GoToUrl(\"https://resend.com/onboarding\")\n Start-Sleep -Seconds 4\n Write-Host \"[BLADE] URL: $($driver.Url)\"\n \n # If still on login, we have a problem - Chrome profile not shared\n if ($driver.Url -match \"login|signin\") {\n Write-Host \"[BLADE] SESSION_NOT_SHARED - need to use Chrome debug port attach instead\"\n $driver.Quit()\n \n # Try attach to running Chrome via debug port\n Write-Host \"[BLADE] Trying Chrome debug port attach...\"\n $chromeExe = \"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\"\n if (!(Test-Path $chromeExe)) { $chromeExe = \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" }\n \n # Kill existing then start with debug port\n Stop-Process -Name \"chrome\" -Force -ErrorAction SilentlyContinue\n Start-Sleep -Seconds 2\n Start-Process $chromeExe -ArgumentList \"--remote-debugging-port=9222\",\"--user-data-dir=$chromeProfile\",\"https://resend.com/onboarding\"\n Start-Sleep -Seconds 5\n \n Write-Host \"[BLADE] Chrome started on debug port 9222 with user profile\"\n Write-Host \"[BLADE] Manual step: user needs to click Add API Key once Chrome is open\"\n \n # POST status back\n $body = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"chrome_opened_debug_port\"\n message = \"Chrome restarted with debug port 9222, Resend onboarding page opened. User can now click Add API Key button manually, or we can send CDP command to click.\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $body -TimeoutSec 10 -ErrorAction SilentlyContinue\n return\n }\n \n # Find and click \"Add API Key\" button\n Write-Host \"[BLADE] Looking for Add API Key button...\"\n Start-Sleep -Seconds 2\n \n $button = $null\n try {\n # Find by text\n $button = $driver.FindElementByXPath(\"//button[contains(., 'Add API Key')]\")\n } catch {\n Write-Host \"[BLADE] XPath not found, trying CSS\"\n try {\n $buttons = $driver.FindElementsByTagName(\"button\")\n foreach ($b in $buttons) {\n if ($b.Text -match \"Add API Key\") { $button = $b; break }\n }\n } catch { }\n }\n \n if ($button) {\n Write-Host \"[BLADE] Button found, clicking...\"\n $button.Click()\n Start-Sleep -Seconds 3\n \n # Dialog should be open now - fill form\n try {\n $nameInput = $driver.FindElementByCssSelector(\"input[name='name']\")\n if (!$nameInput) {\n $nameInput = $driver.FindElementByCssSelector(\"input[placeholder*='ame']\")\n }\n $nameInput.Clear()\n $nameInput.SendKeys(\"wevia-master-blade-\" + (Get-Date -Format 'yyyyMMddHHmm'))\n Write-Host \"[BLADE] Name filled\"\n } catch {\n Write-Host \"[BLADE] Name input err: $_\"\n }\n \n # Select Full access\n try {\n $fullAccess = $driver.FindElementByXPath(\"//*[contains(text(),'Full access')]\")\n $fullAccess.Click()\n Write-Host \"[BLADE] Full access selected\"\n } catch {\n Write-Host \"[BLADE] Full access err: $_\"\n }\n \n Start-Sleep -Seconds 1\n \n # Click Create/Add in dialog\n try {\n $createBtn = $driver.FindElementByXPath(\"//button[text()='Add' or text()='Create']\")\n $createBtn.Click()\n Write-Host \"[BLADE] Create clicked\"\n Start-Sleep -Seconds 4\n } catch {\n Write-Host \"[BLADE] Create err: $_\"\n }\n \n # Extract the new key\n $pageSource = $driver.PageSource\n if ($pageSource -match '(re_[a-zA-Z0-9_]{20,})') {\n $newKey = $matches[1]\n Write-Host \"[BLADE] KEY_FOUND $($newKey.Substring(0,10))...\"\n \n # POST the key to S204 for WEVIA to save\n $body = @{\n action = \"set_key\"\n key = $newKey\n }\n $saveResp = Invoke-RestMethod -Uri \"https://weval-consulting.com/api/resend-send.php\" -Method POST -Body ($body | ConvertTo-Json) -ContentType \"application/json\" -TimeoutSec 10\n Write-Host \"[BLADE] S204_saved: $($saveResp | ConvertTo-Json -Compress)\"\n \n # Also notify blade-api to mark done\n $done = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"success\"\n key_preview = \"$($newKey.Substring(0,10))...\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $done -TimeoutSec 10 -ErrorAction SilentlyContinue\n } else {\n Write-Host \"[BLADE] KEY_NOT_FOUND in page source\"\n $ss = \"$env:TEMP\\resend-state.png\"\n $screenshot = $driver.GetScreenshot()\n $screenshot.SaveAsFile($ss, [OpenQA.Selenium.ScreenshotImageFormat]::Png)\n Write-Host \"[BLADE] Screenshot saved: $ss\"\n }\n } else {\n Write-Host \"[BLADE] BUTTON_NOT_FOUND\"\n }\n \n Start-Sleep -Seconds 2\n $driver.Quit()\n Write-Host \"[BLADE] DONE $(Get-Date)\"\n} catch {\n Write-Host \"[BLADE] FATAL: $_\"\n $body = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"error\"\n error = \"$_\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $body -TimeoutSec 10 -ErrorAction SilentlyContinue\n}\n",
"cmd": "\n# WEVIA via Blade Chrome \u2014 Resend Add API Key automation\n$ErrorActionPreference = \"Continue\"\n$startTime = Get-Date\nWrite-Host \"[BLADE] Resend API Key automation START $startTime\"\n\n# Install Selenium if missing\nif (!(Get-Module -ListAvailable -Name Selenium)) {\n Install-Module Selenium -Force -Scope CurrentUser -AllowClobber -ErrorAction SilentlyContinue\n}\n\ntry {\n Import-Module Selenium -ErrorAction Stop\n \n # Use existing Chrome profile (user already logged into Resend)\n $chromeProfile = \"$env:LOCALAPPDATA\\Google\\Chrome\\User Data\"\n \n $options = New-Object OpenQA.Selenium.Chrome.ChromeOptions\n $options.AddArgument(\"--no-sandbox\")\n $options.AddArgument(\"--disable-blink-features=AutomationControlled\")\n # NOTE: we attach to Balei profile to keep the Resend session cookie\n # $options.AddArgument(\"--user-data-dir=$chromeProfile\")\n # $options.AddArgument(\"--profile-directory=Default\")\n \n $driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)\n Write-Host \"[BLADE] Chrome started\"\n \n # Go to Resend onboarding\n $driver.Navigate().GoToUrl(\"https://resend.com/onboarding\")\n Start-Sleep -Seconds 4\n Write-Host \"[BLADE] URL: $($driver.Url)\"\n \n # If still on login, we have a problem - Chrome profile not shared\n if ($driver.Url -match \"login|signin\") {\n Write-Host \"[BLADE] SESSION_NOT_SHARED - need to use Chrome debug port attach instead\"\n $driver.Quit()\n \n # Try attach to running Chrome via debug port\n Write-Host \"[BLADE] Trying Chrome debug port attach...\"\n $chromeExe = \"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\"\n if (!(Test-Path $chromeExe)) { $chromeExe = \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" }\n \n # Kill existing then start with debug port\n Stop-Process -Name \"chrome\" -Force -ErrorAction SilentlyContinue\n Start-Sleep -Seconds 2\n Start-Process $chromeExe -ArgumentList \"--remote-debugging-port=9222\",\"--user-data-dir=$chromeProfile\",\"https://resend.com/onboarding\"\n Start-Sleep -Seconds 5\n \n Write-Host \"[BLADE] Chrome started on debug port 9222 with user profile\"\n Write-Host \"[BLADE] Manual step: user needs to click Add API Key once Chrome is open\"\n \n # POST status back\n $body = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"chrome_opened_debug_port\"\n message = \"Chrome restarted with debug port 9222, Resend onboarding page opened. User can now click Add API Key button manually, or we can send CDP command to click.\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $body -TimeoutSec 10 -ErrorAction SilentlyContinue\n return\n }\n \n # Find and click \"Add API Key\" button\n Write-Host \"[BLADE] Looking for Add API Key button...\"\n Start-Sleep -Seconds 2\n \n $button = $null\n try {\n # Find by text\n $button = $driver.FindElementByXPath(\"//button[contains(., 'Add API Key')]\")\n } catch {\n Write-Host \"[BLADE] XPath not found, trying CSS\"\n try {\n $buttons = $driver.FindElementsByTagName(\"button\")\n foreach ($b in $buttons) {\n if ($b.Text -match \"Add API Key\") { $button = $b; break }\n }\n } catch { }\n }\n \n if ($button) {\n Write-Host \"[BLADE] Button found, clicking...\"\n $button.Click()\n Start-Sleep -Seconds 3\n \n # Dialog should be open now - fill form\n try {\n $nameInput = $driver.FindElementByCssSelector(\"input[name='name']\")\n if (!$nameInput) {\n $nameInput = $driver.FindElementByCssSelector(\"input[placeholder*='ame']\")\n }\n $nameInput.Clear()\n $nameInput.SendKeys(\"wevia-master-blade-\" + (Get-Date -Format 'yyyyMMddHHmm'))\n Write-Host \"[BLADE] Name filled\"\n } catch {\n Write-Host \"[BLADE] Name input err: $_\"\n }\n \n # Select Full access\n try {\n $fullAccess = $driver.FindElementByXPath(\"//*[contains(text(),'Full access')]\")\n $fullAccess.Click()\n Write-Host \"[BLADE] Full access selected\"\n } catch {\n Write-Host \"[BLADE] Full access err: $_\"\n }\n \n Start-Sleep -Seconds 1\n \n # Click Create/Add in dialog\n try {\n $createBtn = $driver.FindElementByXPath(\"//button[text()='Add' or text()='Create']\")\n $createBtn.Click()\n Write-Host \"[BLADE] Create clicked\"\n Start-Sleep -Seconds 4\n } catch {\n Write-Host \"[BLADE] Create err: $_\"\n }\n \n # Extract the new key\n $pageSource = $driver.PageSource\n if ($pageSource -match '(re_[a-zA-Z0-9_]{20,})') {\n $newKey = $matches[1]\n Write-Host \"[BLADE] KEY_FOUND $($newKey.Substring(0,10))...\"\n \n # POST the key to S204 for WEVIA to save\n $body = @{\n action = \"set_key\"\n key = $newKey\n }\n $saveResp = Invoke-RestMethod -Uri \"https://weval-consulting.com/api/resend-send.php\" -Method POST -Body ($body | ConvertTo-Json) -ContentType \"application/json\" -TimeoutSec 10\n Write-Host \"[BLADE] S204_saved: $($saveResp | ConvertTo-Json -Compress)\"\n \n # Also notify blade-api to mark done\n $done = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"success\"\n key_preview = \"$($newKey.Substring(0,10))...\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $done -TimeoutSec 10 -ErrorAction SilentlyContinue\n } else {\n Write-Host \"[BLADE] KEY_NOT_FOUND in page source\"\n $ss = \"$env:TEMP\\resend-state.png\"\n $screenshot = $driver.GetScreenshot()\n $screenshot.SaveAsFile($ss, [OpenQA.Selenium.ScreenshotImageFormat]::Png)\n Write-Host \"[BLADE] Screenshot saved: $ss\"\n }\n } else {\n Write-Host \"[BLADE] BUTTON_NOT_FOUND\"\n }\n \n Start-Sleep -Seconds 2\n $driver.Quit()\n Write-Host \"[BLADE] DONE $(Get-Date)\"\n} catch {\n Write-Host \"[BLADE] FATAL: $_\"\n $body = @{\n k = \"BLADE2026\"\n task_id = \"resend_click_add\"\n status = \"error\"\n error = \"$_\"\n }\n Invoke-RestMethod -Uri \"https://weval-consulting.com/api/blade-api.php\" -Method POST -Body $body -TimeoutSec 10 -ErrorAction SilentlyContinue\n}\n",
"status": "pending",
"created": "2026-04-20T02:48:12+00:00",
"created_by": "opus-v5.9.6-wevia-blade-bridge",
"expected_result": "Clicks Add API Key button in Resend, creates Full Access key, POSTs to /api/resend-send.php?action=set_key"
}