web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

omnichannel-chat-widget: How can we initiate the chat in LiveChatWidget programmatically?

(1) ShareShare
ReportReport
Posted on by 2
I'm trying to customize the LiveChatWidget [@microsoft/omnichannel-chat-widget](https://github.com/microsoft/omnichannel-chat-widget). But when I add the onSubmit function that is derived from preChatSurveyPaneProps -> controlProps -> onSubmit to validate the input fields of preChatSurveyPane, the liveCHateWidget is not initiating the chat when I click on submit.
 
import { OmnichannelChatSDK } from /@microsoft/omnichannel-chat-sdk/;
import { LiveChatWidget } from /@microsoft/omnichannel-chat-widget/;
import {
  InputValidationPane,
  ChatButton,
  PreChatSurveyPane,
from /@microsoft/omnichannel-chat-components/;
import React, { useEffectuseState } from /react/;
 
const getOmnichannelChatConfig = () => {
  // add your own OC setting, hard-coded just for sample, should be replaced with a better handling
  const omnichannelConfig = {
    orgId: /85007ef2-3740-40f7-99c4-385ec02041ea/// dummy config
    orgUrl:
      https://d74b6a9ace5c43408eb05789f931ca-crm15.omnichannelengagementhub.com/// dummy config
    widgetId: /551b5707-0748-4a63-8eee-7b41bfbd3b95/// dummy config
  };
  return omnichannelConfig;
};
 
const ChatWidgetV1 = () => {
  const [liveChatWidgetPropssetLiveChatWidgetProps] = useState(null);
 
  const init = async () => {
    const omnichannelConfig = getOmnichannelChatConfig();
    const chatSDK = new OmnichannelChatSDK(omnichannelConfig);
    await chatSDK.initialize();
    const chatConfig = await chatSDK.getLiveChatConfig();
 
    const liveChatWidgetProps = {
      styleProps: {
        generalStyles: {
          width: /400px/,
          height: /600px/,
          bottom: /30px/,
          right: /30px/,
        },
      },
      chatSDK,
      chatConfig,
      webChatContainerProps: {
        disableMarkdownMessageFormatting: false//setting the default to true for a known issue with markdown
      },
    };
    setLiveChatWidgetProps(liveChatWidgetProps);
  };
 
  useEffect(() => {
    init();
  }, []);
 
  
 
  return (
    <div>
      {liveChatWidgetProps && (
        <LiveChatWidget
          {...liveChatWidgetProps}
          preChatSurveyPaneProps={{
            controlProps: {
              onSubmit: async (values=> {
                try {
                  console.log(/values/values);
                } catch (error) {
                  console.log(/CustomError/error);
                }
              },
            },
          }}
        ></LiveChatWidget>
      )}
    </div>
  );
};
 
export default ChatWidgetV1;

if i remove the **onSubmit** function from **LiveChatWidget** props that is drived preChatSurveyPaneProps -> controlProps -> onSubmit, click on submit button in **LiveChatWidget** , chat inititated successfully.
 



I want to initiate a new chat when I click on submit button,
when i click on submit, I need to validate the form input values if the values are fine then send these values and initiated a new chat through those values. But i didn't find any solution on how to trigger a new chat in onSubmite function.
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans