thanks for your reply. the AI told me to do this structure in VSCode:
IGEL-Tech_Chatbot1/
├── Controllers/
├── Languages/
├── Templates/
└── css/
then, in IGEL-Tech_Chatbot1/addon.json
{
"id": "igel-tech_chatbot1",
"version": "1.0",
"title": "IGEL-Tech Chatbot1",
"description": "Integriert den IGEL-Tech Chatbot1, der automatisch auf neue Beiträge reagiert.",
"authors": [
{
"name": "Ihr Name",
"email": "IhreEmail@example.com",
"url": "https://feed.vereinige.ch"
}
],
"compatible": "elkarte-1.*",
"type": "mod",
"license": "MIT",
"install": {
"run_on_load": true
}
}
IGEL-Tech_Chatbot1/Controllers/ChatbotController.php
<?php
namespace ElkArte\Extensions\Chatbot;
use ElkArte\sources\extensions\AbstractController;
class ChatbotController extends AbstractController
{
public function load()
{
// Hooks registrieren
$this->add_hook('integrate_post_mod', 'onPostMod');
}
public function onPostMod($msgOptions, $topic, $posterId, $isNewTopic, $msgTime, $posterName, $posterEmail, $smileysEnabled)
{
// Nur auf neue Beiträge reagieren
if (!$isNewTopic) {
$message = $msgOptions['body'];
$response = $this->sendToChatbot($message);
if ($response) {
$this->createPost($topic, $response, $this->getChatbotUserId());
}
}
}
private function sendToChatbot($message)
{
$apiKey = get_option('chatbot_api_key');
$url = 'https://api.openai.com/v1/chat/completions';
$data = [
'model' => 'gpt-4',
'messages' => [
['role' => 'user', 'content' => $message]
],
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
error_log('Chatbot API Fehler: ' . curl_error($ch));
curl_close($ch);
return false;
}
curl_close($ch);
$responseData = json_decode($response, true);
return $responseData['choices'][0]['message']['content'] ?? null;
}
private function createPost($topicId, $message, $memberId)
{
global $smcFunc;
$insertData = [
'id_member' => $memberId,
'id_topic' => $topicId,
'subject' => 'Antwort vom Chatbot',
'body' => $message,
'poster_time' => time(),
];
$smcFunc['db_insert']('insert',
'{db_prefix}messages',
['id_member' => 'int', 'id_topic' => 'int', 'subject' => 'string-65534', 'body' => 'string-65534', 'poster_time' => 'int'],
[$insertData['id_member'], $insertData['id_topic'], $insertData['subject'], $insertData['body'], $insertData['poster_time']],
['id_msg']
);
updateLastMessages($topicId, $insertData['poster_time']);
}
private function getChatbotUserId()
{
return intval(get_option('chatbot_user_id'));
}
}
IGEL-Tech_Chatbot1/Languages/German.php
<?php
$txt['chatbot_plugin_name'] = 'IGEL-Tech Chatbot1';
$txt['chatbot_plugin_desc'] = 'Integriert den IGEL-Tech Chatbot1, der automatisch auf neue Beiträge reagiert.';
$txt['chatbot_api_key'] = 'Chatbot API-Schlüssel';
$txt['chatbot_user_id'] = 'Chatbot Benutzer-ID';
$txt['chatbot_settings'] = 'Chatbot Einstellungen';
$txt['chatbot_save'] = 'Speichern';
$txt['chatbot_invalid_api_key'] = 'Ungültiger API-Schlüssel. Bitte überprüfen Sie Ihre Eingabe.';
$txt['chatbot_invalid_user_id'] = 'Ungültige Benutzer-ID. Bitte überprüfen Sie Ihre Eingabe.';
IGEL-Tech_Chatbot1/Templates/ChatbotSettings.template.php
<?php
// Verhindern des direkten Zugriffs auf die Datei
if (!defined('ELKARTE'))
die('No access...');
function template_chatbot_settings()
{
global $context, $txt;
echo '
<div class="content">
<form action="' . $context['post_url'] . '" method="post" accept-charset="UTF-8">
<div class="input-group">
<label for="chatbot_api_key">' . $txt['chatbot_api_key'] . '</label>
<input type="text" name="chatbot_api_key" id="chatbot_api_key" value="' . htmlspecialchars(get_option('chatbot_api_key')) . '" required />
</div>
<div class="input-group">
<label for="chatbot_user_id">' . $txt['chatbot_user_id'] . '</label>
<input type="number" name="chatbot_user_id" id="chatbot_user_id" value="' . intval(get_option('chatbot_user_id')) . '" required />
</div>
<input type="submit" name="save" value="' . $txt['chatbot_save'] . '" />
</form>
</div>';
}
then zip it and via FTP place it in [my server]feed.vereinige.ch/public_html/packages/
but it did not work, also un-zipped and neither the /addons nor the uploading from my pc in the administrator dashboard.
it would be nice to have a chatbot in a forum, wouldn't it?