diff --git a/backend/alembic/versions/6d562f86c78b_remove_default_bot.py b/backend/alembic/versions/6d562f86c78b_remove_default_bot.py new file mode 100644 index 000000000000..3e7097b87bc3 --- /dev/null +++ b/backend/alembic/versions/6d562f86c78b_remove_default_bot.py @@ -0,0 +1,45 @@ +"""remove default bot + +Revision ID: 6d562f86c78b +Revises: 177de57c21c9 +Create Date: 2024-11-22 11:51:29.331336 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = "6d562f86c78b" +down_revision = "177de57c21c9" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.execute( + sa.text( + """ + DELETE FROM slack_bot + WHERE name = 'Default Bot' + AND bot_token = '' + AND app_token = '' + AND NOT EXISTS ( + SELECT 1 FROM slack_channel_config + WHERE slack_channel_config.slack_bot_id = slack_bot.id + ) + """ + ) + ) + + +def downgrade() -> None: + op.execute( + sa.text( + """ + INSERT INTO slack_bot (name, enabled, bot_token, app_token) + SELECT 'Default Bot', true, '', '' + WHERE NOT EXISTS (SELECT 1 FROM slack_bot) + RETURNING id; + """ + ) + ) diff --git a/web/src/app/admin/bots/SlackBotCreationForm.tsx b/web/src/app/admin/bots/SlackBotCreationForm.tsx index bedca7623808..8a113af05f4a 100644 --- a/web/src/app/admin/bots/SlackBotCreationForm.tsx +++ b/web/src/app/admin/bots/SlackBotCreationForm.tsx @@ -1,9 +1,12 @@ "use client"; +import CardSection from "@/components/admin/CardSection"; import { usePopup } from "@/components/admin/connectors/Popup"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { SlackTokensForm } from "./SlackTokensForm"; +import { SourceIcon } from "@/components/SourceIcon"; +import { AdminPageTitle } from "@/components/admin/Title"; export const NewSlackBotForm = ({}: {}) => { const [formValues] = useState({ @@ -17,15 +20,21 @@ export const NewSlackBotForm = ({}: {}) => { return (
- {popup} -
- -
+ } + title="New Slack Bot" + /> + + {popup} +
+ +
+
); }; diff --git a/web/src/app/admin/bots/SlackBotTokensForm.tsx b/web/src/app/admin/bots/SlackBotTokensForm.tsx deleted file mode 100644 index 03c889756037..000000000000 --- a/web/src/app/admin/bots/SlackBotTokensForm.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import { Form, Formik } from "formik"; -import * as Yup from "yup"; -import { PopupSpec } from "@/components/admin/connectors/Popup"; -import { SlackBot } from "@/lib/types"; -import { TextFormField } from "@/components/admin/connectors/Field"; -import CardSection from "@/components/admin/CardSection"; -import { Button } from "@/components/ui/button"; -import { updateSlackBot, SlackBotCreationRequest } from "./new/lib"; - -interface SlackBotTokensFormProps { - onClose: () => void; - setPopup: (popupSpec: PopupSpec | null) => void; - existingSlackApp?: SlackBot; - onTokensSet?: (tokens: { bot_token: string; app_token: string }) => void; - embedded?: boolean; - noForm?: boolean; -} - -export const SlackBotTokensForm = ({ - onClose, - setPopup, - existingSlackApp, - onTokensSet, - embedded = true, - noForm = true, -}: SlackBotTokensFormProps) => { - const Wrapper = embedded ? "div" : CardSection; - - const FormWrapper = noForm ? "div" : Form; - - return ( - - { - if (embedded && onTokensSet) { - onTokensSet(values); - return; - } - - formikHelpers.setSubmitting(true); - const response = await updateSlackBot( - existingSlackApp?.id || 0, - values as SlackBotCreationRequest - ); - formikHelpers.setSubmitting(false); - if (response.ok) { - setPopup({ - message: "Successfully set Slack tokens!", - type: "success", - }); - onClose(); - } else { - const errorMsg = await response.text(); - setPopup({ - message: `Error setting Slack tokens - ${errorMsg}`, - type: "error", - }); - } - }} - > - {({ isSubmitting }) => ( - - - - {!embedded && ( -
- -
- )} -
- )} -
-
- ); -}; diff --git a/web/src/app/admin/bots/SlackBotUpdateForm.tsx b/web/src/app/admin/bots/SlackBotUpdateForm.tsx index 35d6cbcd032d..9eec40eeb95f 100644 --- a/web/src/app/admin/bots/SlackBotUpdateForm.tsx +++ b/web/src/app/admin/bots/SlackBotUpdateForm.tsx @@ -75,17 +75,19 @@ export const ExistingSlackBotForm = ({ return (
{popup} -
+
- + +
+
+ handleUpdateField("name", value)} + scale={2.1} + />
- handleUpdateField("name", value)} - scale={2.5} - />
@@ -108,6 +110,7 @@ export const ExistingSlackBotForm = ({ onClick={() => setShowDeleteModal(true)} icon={FiTrash} tooltip="Click to delete" + className="border h-[42px]" > Delete @@ -123,14 +126,15 @@ export const ExistingSlackBotForm = ({ refreshSlackBot={refreshSlackBot} setPopup={setPopup} router={router} + onValuesChange={(values) => setFormValues(values)} />
)}
-
-
+
+
void; setPopup: (popup: { message: string; type: "error" | "success" }) => void; router: any; -}) => ( - { - formikHelpers.setSubmitting(true); + onValuesChange?: (values: any) => void; +}) => { + useEffect(() => { + if (onValuesChange) { + onValuesChange(initialValues); + } + }, [initialValues]); - let response; - if (isUpdate) { - response = await updateSlackBot(existingSlackBotId!, values); - } else { - response = await createSlackBot(values); - } - formikHelpers.setSubmitting(false); - if (response.ok) { - if (refreshSlackBot) { - refreshSlackBot(); + return ( + { + formikHelpers.setSubmitting(true); + + let response; + if (isUpdate) { + response = await updateSlackBot(existingSlackBotId!, values); + } else { + response = await createSlackBot(values); } - const responseJson = await response.json(); - const botId = isUpdate ? existingSlackBotId : responseJson.id; - setPopup({ - message: isUpdate - ? "Successfully updated Slack Bot!" - : "Successfully created Slack Bot!", - type: "success", - }); - router.push(`/admin/bots/${encodeURIComponent(botId)}`); - } else { - const responseJson = await response.json(); - const errorMsg = responseJson.detail || responseJson.message; - setPopup({ - message: isUpdate - ? `Error updating Slack Bot - ${errorMsg}` - : `Error creating Slack Bot - ${errorMsg}`, - type: "error", - }); - } - }} - enableReinitialize={true} - > - {({ isSubmitting, setFieldValue, values }) => ( -
- {!isUpdate && ( -
-
- + formikHelpers.setSubmitting(false); + if (response.ok) { + if (refreshSlackBot) { + refreshSlackBot(); + } + const responseJson = await response.json(); + const botId = isUpdate ? existingSlackBotId : responseJson.id; + setPopup({ + message: isUpdate + ? "Successfully updated Slack Bot!" + : "Successfully created Slack Bot!", + type: "success", + }); + router.push(`/admin/bots/${encodeURIComponent(botId)}`); + } else { + const responseJson = await response.json(); + const errorMsg = responseJson.detail || responseJson.message; + setPopup({ + message: isUpdate + ? `Error updating Slack Bot - ${errorMsg}` + : `Error creating Slack Bot - ${errorMsg}`, + type: "error", + }); + } + }} + enableReinitialize={true} + > + {({ isSubmitting, setFieldValue, values }) => ( + + {!isUpdate && ( +
+
- -
- )} + )} - {!isUpdate && ( -
- Please enter your Slack Bot Token and Slack App Token to give - Danswerbot access to your Slack! + {!isUpdate && ( +
+ + Please refer to our{" "} + + guide + {" "} + if you are not sure how to get these tokens! +
+ )} + + +
+
- )} - - -
- -
- - )} - -); + + )} + + ); +}; diff --git a/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx b/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx index 811bad4081af..9a8caad2ad5c 100644 --- a/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx +++ b/web/src/app/admin/bots/[bot-id]/channels/SlackChannelConfigCreationForm.tsx @@ -261,10 +261,12 @@ export const SlackChannelConfigCreationForm = ({
- +
+ +
{showAdvancedOptions && (
@@ -369,7 +371,7 @@ export const SlackChannelConfigCreationForm = ({