import { useContext, useEffect, useRef, useState } from 'react'; import CustomInstructions from '../../components/CustomInstructions/CustomInstructions'; import Input from '../../components/Input/input'; import VisibleOnPages from '../../components/VisibleOnPages'; import { PremiumSettings } from '../../types/types'; import { useNavigate } from 'react-router-dom'; import { PremiumSettingsContext } from '../../context/contexts'; import Loading from '../../components/Loading'; import NoPoweredBy from '../../components/NoPoweredBy'; export default function PremiumFeatures() { const [mainGoal, setMainGoal] = useState(''); const [customInstructions, setCustomInstructions] = useState([]); const [loading, setLoading] = useState(true); const oldMainGoal = useRef(mainGoal); const navigate = useNavigate(); const premiumSettings = useContext(PremiumSettingsContext); useEffect(() => { if (premiumSettings) { setLoading(false); setPremiumSettings(premiumSettings); } }, [premiumSettings]); function setPremiumSettings(premiumSettings: PremiumSettings): void { // Set the main goal if it is set if (premiumSettings.mainGoal) { setMainGoal(premiumSettings.mainGoal); oldMainGoal.current = premiumSettings.mainGoal; } else { const mainGoal = 'your goal is to help users to find things on this website.'; setMainGoal(mainGoal); oldMainGoal.current = mainGoal; } // Set the custom instructions if they are set if (premiumSettings.customInstructions) { setCustomInstructions(premiumSettings.customInstructions); } else { setCustomInstructions([ 'Use the ai search index "siteforge-chat-data-index" to find information about the site.', 'Do not provide answers unrelated to questions about the website. If a user asks a question that is not related to the website, you can respond that you can only help with questions about the current website.', 'If you cant find a good answer to a question, you can respond that you are not sure and ask the user reframe the question.', ]); } } async function postMainGoal(value: string): Promise { try { const response = await fetch( `${wpApiSettings.root}botfoundry/v1/set-main-goal`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': wpApiSettings.nonce, // Include the nonce for authentication }, body: JSON.stringify({ mainGoal: value }), } ); if (!response.ok) { throw new Error('Failed to post main goal'); } } catch (error) { console.error(error); } setMainGoal(value); oldMainGoal.current = value; } if (loading) { return ; } return ( <> {!premiumSettings.active ? (

Upgrade to premium to unlock these features

With premium you can set the main goal for the chat bot, add custom instructions and set the chat bot to only be visible on certain pages.

) : null}

Chat bot main goal

Here you can set the main goal for the chat bot. This is the main purpose of the chat bot and should be a short sentence that describes the main goal of the chat bot.

{ setMainGoal(value); }} className="large-input mb-16" disabled={!premiumSettings.active} />



); }