feat: Alexa TTS API サーバーを追加
- alexa-api/: Echo デバイスに TTS を送る Node.js API サーバー
- server.js: alexa-remote2 を使わない直接 Alexa API 実装
- GET /api/language で CSRF トークン取得
- GET /api/bootstrap でカスタマー ID 取得
- POST /api/behaviors/preview で TTS 実行
- Dockerfile + docker-compose.yml: windmill_windmill-internal ネットワーク接続
- auth4.js: Amazon Japan OpenID フローで Cookie 取得(WORKING)
- scripts/alexa_speak.ts: Windmill から alexa-api を呼び出すスクリプト
Windmill (u/admin/alexa_speak) → alexa_api:3500/speak → Echo デバイス の
パスで日本語 TTS が動作することを確認済み。
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
76
alexa-api/auth3.js
Normal file
76
alexa-api/auth3.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* auth3.js - メール/パスワードで直接認証(2FA なしのアカウント向け)
|
||||
*
|
||||
* 使い方:
|
||||
* AMAZON_EMAIL="xxx@xxx.com" AMAZON_PASSWORD="yourpass" node auth3.js
|
||||
*
|
||||
* 成功すると .env を更新して終了します。
|
||||
*/
|
||||
|
||||
const AlexaRemote = require('alexa-remote2');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const email = process.env.AMAZON_EMAIL;
|
||||
const password = process.env.AMAZON_PASSWORD;
|
||||
|
||||
if (!email || !password) {
|
||||
console.error('[ERROR] 環境変数 AMAZON_EMAIL と AMAZON_PASSWORD を設定してください');
|
||||
console.error(' 例: AMAZON_EMAIL="xxx@xxx.com" AMAZON_PASSWORD="pass" node auth3.js');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`[INFO] ${email} でログイン試行中...`);
|
||||
|
||||
const alexa = new AlexaRemote();
|
||||
|
||||
alexa.init(
|
||||
{
|
||||
email,
|
||||
password,
|
||||
alexaServiceHost: 'alexa.amazon.co.jp',
|
||||
amazonPage: 'amazon.co.jp',
|
||||
acceptLanguage: 'ja-JP',
|
||||
useWsMqtt: false,
|
||||
setupProxy: false,
|
||||
logger: (msg) => {
|
||||
if (!msg.includes('verbose') && !msg.includes('Bearer')) {
|
||||
console.log('[alexa]', msg);
|
||||
}
|
||||
},
|
||||
onSucess: (refreshedCookie) => {
|
||||
saveCookie(refreshedCookie, 'onSucess refresh');
|
||||
},
|
||||
},
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error('[ERROR] 認証失敗(詳細):', err);
|
||||
console.error('\n考えられる原因:');
|
||||
console.error(' - パスワードが違う');
|
||||
console.error(' - Amazon が CAPTCHA を要求している(後で再試行)');
|
||||
console.error(' - 2FA が実際は有効になっている');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 認証成功
|
||||
const cookie = alexa.cookie;
|
||||
saveCookie(cookie, 'init success');
|
||||
process.exit(0);
|
||||
}
|
||||
);
|
||||
|
||||
function saveCookie(cookie, source) {
|
||||
if (!cookie) {
|
||||
console.error(`[${source}] Cookie が空です`);
|
||||
return;
|
||||
}
|
||||
const cookieStr = typeof cookie === 'string' ? cookie : JSON.stringify(cookie);
|
||||
const envPath = path.join(__dirname, '.env');
|
||||
fs.writeFileSync(envPath, 'ALEXA_COOKIE=' + cookieStr + '\n');
|
||||
|
||||
console.log('\n==============================================');
|
||||
console.log(' 認証成功!');
|
||||
console.log('==============================================');
|
||||
console.log('.env を更新しました:', envPath);
|
||||
console.log('Cookie length:', cookieStr.length);
|
||||
}
|
||||
Reference in New Issue
Block a user