livechat / chat-widget-adapters

This project contains a set of libraries for adapting LiveChat Chat Widget with certain frontend frameworks
https://developers.livechat.com
MIT License
22 stars 8 forks source link

Programmatically start chat #77

Open tmyers101 opened 1 year ago

tmyers101 commented 1 year ago

This is more of a question. Is there a way to programmatically start a chat in the React Chat Widget? I want to start a chat when a user clicks on a button that I created.

danielahristova commented 1 year ago

Has been proposed here #71 , guess it's not a thing yet

umitalp commented 1 year ago

Seems like the it updates the visibility of the widget when the prop is changed here

Maybe changing the visibility prop of the LiveChatWidget will help, something like;

import { FunctionComponent, useState } from 'react';
import { LiveChatWidget, WidgetState, useWidgetIsReady } from '@livechat/widget-react';

const LiveChatWidgetSection: FunctionComponent = () => {
    const isWidgetReady = useWidgetIsReady();
    const [liveChatWidgetVisibility, setLiveChatWidgetVisibility] = useState<WidgetState['visibility']>('hidden');

    if (!isWidgetReady) {
        return null;
    }

    return (
        <>
            <button onClick={() => setLiveChatWidgetVisibility('maximized')}>
                Change LiveChat Widget Visibility
            </button>
            <LiveChatWidget
                license='your_license_here'
                visibility={liveChatWidgetVisibility}
            />
        </>
    );
};

export default LiveChatWidgetSection;