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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / Form submission fails ...
Copilot Studio
Answered

Form submission fails when posted on a website

(1) ShareShare
ReportReport
Posted on by 6

After uploading the chatbot service to the website, the form submission function that was originally working does not work.

Is there any reason why the function below doesn't work? It just keeps refreshing.

 

 

// Add your BOT ID below
var BOT_ID = "";
var theURL = "https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken?botId=" + BOT_ID;

const store = window.WebChat.createStore(
 {},
 function (store) {
 return function (next) {
 return function (action) {
 if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
 store.dispatch({
 meta: {
 method: "keyboard",
 },
 payload: {
 activity: {
 channelData: { postBack: true, },
 text: "hello",
 type: "message",
 },
 },
 type: "DIRECT_LINE/POST_ACTIVITY",
 });
 }
 return next(action);
 }
 }
 }
);

fetch(theURL)
 .then(function (response) {
 return response.json()
 })
 .then(function (conversationInfo) {
 window.WebChat.renderWebChat(
 {
 directLine: window.WebChat.createDirectLine({
 token: conversationInfo.token,
 }),
 store: store,
 styleOptions: styleOptions
 },
 document.getElementById('webchat'));
 })
 .catch(function (err) { console.log('An error occurred: ', err) });

function Check() {
 form.submit();
 }

 

 

Categories:
I have the same question (0)
  • CU22081450-0 Profile Picture
    Most Valuable Professional on at

    Hi @sllll ,

     

    Did you change the Bot ID?

     

    And try to use this script in your page:

    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>

     

    ---
    If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.

    Thanks!
    Renato Romão
    https://www.linkedin.com/in/renatoromao/

  • sllll Profile Picture
    6 on at

    I used the script, and I also entered the bot ID.

    The form submission method cannot be used on the page where the bot is applied.

  • Verified answer
    chass Profile Picture
    Microsoft Employee on at

    Pasting your code into my HTML page it works great for me...Suggesting the issue may be in your HTML page. 

    Rather than trouble shooting your HTML i thought i would include the page i was using that works below. 

    More information about this topic can be found here: 

    https://powervirtualagents.microsoft.com/en-us/blog/make-your-power-virtual-agents-bot-start-the-conversation-using-a-custom-canvas/

     

     

     

    <!DOCTYPE html>
    <html>
    <head>
    <title>Contoso Sample Web Chat</title>
    <!-- This styling is for the canvas demonstration purposes. It is recommended
    that style is moved to separate file for organization in larger projects -->
    <style>
    html, body {
    height: 100%;
    }

    body {
    margin: 0;
    }

    h1 {
    font-size: 16px;
    font-family: Segoe UI;
    line-height: 20px;
    color: whitesmoke;
    display: table-cell;
    padding: 13px 0px 0px 20px;
    }

    .heading {
    background-color: black;
    height: 50px;
    }

    .main {
    margin: 18px;
    border-radius: 4px;
    }

    div[role="form"] {
    background-color: black;
    }

    #webchat {
    position: fixed;
    height: calc(100% - 50px);
    width: 100%;
    top: 50px;
    overflow: hidden;
    }
    </style>
    </head>
    <body>
    <div>
    <div class="heading">

    <!-- Change the h1 text to change the bot name -->
    <h1>Contoso Bot Name</h1>

    </div>
    <div id="webchat" role="main"></div>
    </div>
    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <script>
    const styleOptions = {
    // Add styleOptions to customize web chat canvas
    hideUploadButton: true
    };

    // Add your BOT ID below
    var BOT_ID = "a6a0c899-c4af-4a23-922e-60850b5d4cf1";
    var theURL = "https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken?botId=" + BOT_ID;

    const store = window.WebChat.createStore(
    {},
    function (store) {
    return function (next) {
    return function (action) {
    if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
    store.dispatch({
    meta: {
    method: "keyboard",
    },
    payload: {
    activity: {
    channelData: { postBack: true, },
    text: "hello",
    type: "message",
    },
    },
    type: "DIRECT_LINE/POST_ACTIVITY",
    });
    }
    return next(action);
    }
    }
    }
    );

    fetch(theURL)
    .then(function (response) {
    return response.json()
    })
    .then(function (conversationInfo) {
    window.WebChat.renderWebChat(
    {
    directLine: window.WebChat.createDirectLine({
    token: conversationInfo.token,
    }),
    store: store,
    styleOptions: styleOptions
    },
    document.getElementById('webchat'));
    })
    .catch(function (err) { console.log('An error occurred: ', err) });

    function Check() {
    form.submit();
    }

    </script>
    </body>
    </html>

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 Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Copilot Studio

#1
Valantis Profile Picture

Valantis 835

#2
Vish WR Profile Picture

Vish WR 294

#3
Haque Profile Picture

Haque 248

Last 30 days Overall leaderboard