Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedding in an Iframe is not possible #55

Open
veserai opened this issue Apr 9, 2024 · 1 comment
Open

Embedding in an Iframe is not possible #55

veserai opened this issue Apr 9, 2024 · 1 comment

Comments

@veserai
Copy link

veserai commented Apr 9, 2024

The standard dify-web docker container allows to embed the Chatbot in an Iframe on a website.
As I needed to customize the frontend, I followed the instructions and deployed the webapp-conversations frontend on vercel.
It runs perfectly when I open the Vercel URL directly. As soon as I embed it into an Iframe, I always get the error, that the chatbot is still responding, when I try to send a second message.
error_chatbot

Already tested:

  • Using a Reverseproxy in front of Vercel
  • Using Browser Dev Tools to find possible CORS Errors ect.
  • Using other Browsers: Chrome, Safari -> Not working, Firefox-> Working
@veserai
Copy link
Author

veserai commented Apr 11, 2024

I was able to fix it on my own. The problem was: /app/compontents/index.tsx: The "oncompleted" function fails while fetching the conversations.id . Therefore the bot never reaches the state, where the "setResponsingFalse()" is set.
I rewrote the async onCompleted like this:

async onCompleted(hasError?: boolean) {
        // Immediately set the chatbot as not responding, regardless of potential errors in fetching conversations
        setResponsingFalse();
        
        if (hasError) {
          return; // Early return if there was an error in the chat message operation
        }

        try {
          // Attempt to fetch all conversations and generate a new name for the conversation
          const { data: allConversations }: any = await fetchConversations();
          if (allConversations && allConversations.length > 0) {
            const newItem: any = await generationConversationName(allConversations[0].id);
            
            // Proceed with setting new conversation information and resetting state as needed
            const newAllConversations = produce(allConversations, (draft: any) => {
              draft[0].name = newItem.name;
            });
            setConversationList(newAllConversations as any);
            
            // Additional logic to reset inputs and conversation IDs as needed
            if (getConversationIdChangeBecauseOfNew()) {
              setConversationIdChangeBecauseOfNew(false);
              resetNewConversationInputs();
              setChatNotStarted();
              setCurrConversationId(allConversations[0].id, APP_ID, true);
            }
          } else {
            // Handle the case where no conversations are returned
            console.error("No conversations were fetched.");
          }
        } catch (error) {
          console.error("An error occurred while fetching conversations or generating a new conversation name:", error);
          // Here, handle the error as needed, possibly setting additional error states or displaying a message to the user
        }
      },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant