Skip to main content
Recent Posts
52
Support / Re: AI Chatbot
Last post by Gabriel -
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
Code: [Select]
{
    "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
Code: [Select]
<?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
Code: [Select]
<?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
Code: [Select]
<?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?
53
Support / Re: AI Chatbot
Last post by ahrasis -
You should consult them on how to it in details, as we do not know it, moreover to help you with it. Or you can find and hire a freelance developer to do it for you and your forum.
54
Support / AI Chatbot
Last post by Gabriel -
hello, i am not experienced with coding.
can somebody help me to install a custom chatbot in my forum (https://feed.vereinige.ch)?
openai o1 told me to create an account for the chatbot and subsequently gave me 2 different solutions:
1. create a folder in sources/extensions and add the code supplied by o1
2. create a custom package with instructions by o1 and upload via admin board
neither of them worked.

the bot should reply to questions in https://feed.vereinige.ch/index.php?board=10.0

i speak mainly german. help in other languages also welcome.
thanks in advance
56
Chit Chat / 25
Last post by Steeley -
Here we go again...