59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
require('dotenv').config();
|
|
const express = require('express');
|
|
const bodyParser = require('body-parser');
|
|
const axios = require('axios');
|
|
|
|
app.use(bodyParser.json());
|
|
|
|
module.exports = (app) => {
|
|
// LINE WORKS Webhookエンドポイント
|
|
app.post('/nextgpt', async (req, res) => {
|
|
try {
|
|
const { source, content } = req.body;
|
|
|
|
// LINE WORKSからのメッセージ
|
|
const userMessage = content.text;
|
|
const userId = source.accountId;
|
|
|
|
console.log(`Received message: "${userMessage}" from User: "${userId}"`);
|
|
|
|
// anythingLLMにメッセージを送信して応答を取得
|
|
const llmResponse = await axios.post(process.env.ANYTHING_LLM_API, {
|
|
question: userMessage
|
|
});
|
|
|
|
const llmAnswer = llmResponse.data.answer || "申し訳ありませんが、応答を生成できませんでした。";
|
|
|
|
// LINE WORKSに応答を送信
|
|
await axios.post(
|
|
`https://apis.worksmobile.com/r/${process.env.LINEWORKS_BOT_ID}/message/push`,
|
|
{
|
|
botNo: process.env.LINEWORKS_BOT_ID,
|
|
accountId: userId,
|
|
content: {
|
|
type: "text",
|
|
text: llmAnswer
|
|
}
|
|
},
|
|
{
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"consumerKey": process.env.LINEWORKS_API_KEY
|
|
}
|
|
}
|
|
);
|
|
|
|
console.log(`Reply sent to User: "${userId}"`);
|
|
res.status(200).send('OK');
|
|
} catch (error) {
|
|
console.error('Error:', error.message);
|
|
res.status(500).send('Internal Server Error');
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$p.apiUpdate({ id: 186849, data: { ApiVersion: 1.1, ClassHash: { ClassU: ["遠藤 晃太", "(退職) 横井 英治"], ClassV: ["原田 朋保"], ClassW: ["宮倉 由紀"] } }, done: function (data) { console.log(data); }, });
|