86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
//参考スクリプト startLineworksSurvey.js
|
|
// botId = $('#Results_Class001').val();
|
|
// surveyId = $('#Results_Class002').val();
|
|
// targetId = $('#Results_Class003').val();
|
|
|
|
const WEBHOOK_URL = 'https://neo999.next-hd.net/lineworksSurvey/webhook';
|
|
const API_KEY = 'pgqhLFWbDFu4Byz#4afNYX2F6Fa1&$KPjved$8%sUdTQV52caip#EpIKxYUkdd4S';
|
|
|
|
async function sendStartRequest() {
|
|
const botId = $('#Results_Class001').val();
|
|
const surveyId = $('#Results_Class002').val();
|
|
const targetId = $('#Results_Class003').val();
|
|
const resultId = $p.id();
|
|
|
|
if (!surveyId || !targetId || !botId) {
|
|
console.error('surveyId, targetId, botId をソース内で設定してください。');
|
|
return false;
|
|
}
|
|
|
|
if (!API_KEY) {
|
|
console.error('API_KEY is empty. Check config.js / environment.');
|
|
return false;
|
|
}
|
|
|
|
const payload = { surveyId, targetId, botId, resultId };
|
|
const res = await fetch(WEBHOOK_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'x-api-key': API_KEY
|
|
},
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
const text = await res.text();
|
|
let body;
|
|
try {
|
|
body = JSON.parse(text);
|
|
} catch {
|
|
body = { raw: text };
|
|
}
|
|
|
|
if (!res.ok) {
|
|
console.error('Start request failed:', res.status, body);
|
|
process.exit(1);
|
|
}
|
|
/*
|
|
Start request success: {
|
|
result: 'ok',
|
|
sessionId: 'eef7af18-065a-4486-b5a5-9f65bca61d5a',
|
|
message: 'アンケートを開始しました'
|
|
}
|
|
*/
|
|
console.log('Start request success:', body);
|
|
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
アンケート発行処理
|
|
*/
|
|
async function sendSurvey(proccessButton) {
|
|
|
|
let procNum = proccessButton[0].id.replace('Process_', '');
|
|
console.log('Process number:', procNum);
|
|
|
|
if (await sendStartRequest()) {
|
|
// プロセス実行
|
|
$p.setMessage('#Message', JSON.stringify({
|
|
Css: 'alert-success',
|
|
Text: 'アンケートを発行しました'
|
|
}));
|
|
//$p.set($('#Results_Status'), 150);
|
|
|
|
//プロセスを継続
|
|
$p.execProcess($('#Process_' + procNum));
|
|
return true;
|
|
} else {
|
|
$p.setMessage('#Message', JSON.stringify({
|
|
Css: 'alert-error',
|
|
Text: 'アンケートの発行に失敗しました'
|
|
}));
|
|
|
|
return false;
|
|
}
|
|
} |