Giter Site home page Giter Site logo

Comments (12)

rainmakerho avatar rainmakerho commented on July 19, 2024 2

@stevkan , Thanks.
My temporary solution is below,
save current conversationId then call botConnection.end() and remove webchat when stop conversation.
re-create webchat when start conversation.
like BotChatUI.ts

from botframework-directlinejs.

stevkan avatar stevkan commented on July 19, 2024

Hi @rainmakerho,

Can you provide your code so I can see how you are using the commands? Also, to verify, are you using the most recent version of the botchat.js?

from botframework-directlinejs.

rainmakerho avatar rainmakerho commented on July 19, 2024

Hi @stevkan ,
I add 2 button to control stop/resume conversation.

<button onclick="stopConversation()">Stop Conversation</button>
<button onclick="resumeConversation()">Resume Conversation</button>

DirectLine set websocket to false,

const botConnection = new BotChat.DirectLine({
      domain: params['domain'],
      secret: params['s'],
      token: params['t'],
      webSocket: false
    });
function stopConversation() {
      console.log('stopConversation');
      botConnection.end();
    }

    function resumeConversation() {
      console.log('resumeConversation');
      botConnection.connectionStatus$.next(0);
    }

thanks for your help.

from botframework-directlinejs.

stevkan avatar stevkan commented on July 19, 2024

Hi @rainmakerho,

Please see below. The code I have provided is working for me to pause/resume a conversation using BotChat.

The html stop/resume buttons take a value of true/false, respectively.

<button onclick="postButtonStop(true)">Stop Conversation</button>
<button onclick="postButtonResume(false)">Resume Conversation</button>

Clicking the buttons pass the values to the stopConversation and resumeConversation functions which set the states for botConnection.activity$.closed and botConnection.connectionStatus$.isStopped. The two functions also post messages back to the bot using back channel and the conversationMsg function.

<script>
      botConnection.activity$
        .filter(function (activity) {
            return activity.type === 'message' && activity.name === 'conversationMsg';
        })
        .subscribe(function (activity) {
            console.log('"conversationMsg" received with value: ' + activity.text);
            conversationMsg(activity.text);
        });

      function stopConversation(newState) {
        console.log('stopConversation: ' + newState);
        $.when(botConnection.activity$.closed = newState)
          .done(function(){
            botConnection.connectionStatus$.isStopped = newState;
          });
      };
      
      function resumeConversation(newState) {
        console.log('resumeConversation: ' + newState);
        $.when(botConnection.connectionStatus$.isStopped = newState)
          .done(function() {
            botConnection.activity$.closed = newState;
          });
      };
      
      function conversationMsg(msg) {
        console.log(msg);
      };

      function postButtonStop(btnValue) {
        botConnection
          .postActivity({
            from: { id: 'me' },
            name: 'conversationMsg',
            type: 'message',
            text: "Conversation paused"
          })
          .subscribe(function (id) {
            console.log('"conversationMsg" sent');
          });
        stopConversation(btnValue);
      };
      
      function postButtonResume(btnValue) {
        resumeConversation(btnValue);
        botConnection
          .postActivity({
            from: { id: 'me'},
            name: 'conversationMsg',
            type: 'message',
            text: "Conversation resumed"
          })
          .subscribe(function (id) {
            console.log('"conversationMsg" sent');
          });
      }
</script>

The pauseDialog is triggered when the 'Conversation paused' message is posted. The post and trigger happen first followed by the botConnection service being paused. The user is left in the pauseDialog with no usable connection and no secondary function to move them on. The resumeDialog is triggered when the 'Conversation resumed' message is posted. The botConnection is first re-established, then the message is posted. The session.endDialog() is called and the user is returned to the conversation where they left off.

bot.dialog('pauseDialog', [
    function(session) {
        console.log("Conversation paused");
    }
]).triggerAction({
    matches: /Conversation.*paused/i
});

bot.dialog('resumeDialog', [
    function(session) {
       console.log("Conversation resumed");
       session.endDialog();
    }
]).triggerAction({
    matches: /Conversation.*resumed/i
});

I hope this helps. This should be a good starting point for you.
Steve.

from botframework-directlinejs.

rainmakerho avatar rainmakerho commented on July 19, 2024

@stevkan ,

I try your codes. Bot won't get activity when click postButtonStop's button, but webchat still polling.
Thank you.

from botframework-directlinejs.

compulim avatar compulim commented on July 19, 2024

Unfortunately, I am not an expert in that area. You will need to look around DirectLineJS to see how to pause the polling.

from botframework-directlinejs.

stevkan avatar stevkan commented on July 19, 2024

@rainmakerho, I apologize for not answering. I somehow missed your response. Let me take a look and see if there is anything on polling.

from botframework-directlinejs.

rainmakerho avatar rainmakerho commented on July 19, 2024

@stevkan , Thank you.

from botframework-directlinejs.

compulim avatar compulim commented on July 19, 2024

Worked with @stevkan offline. Looks like DirectLineJS doesn't like the idea to pause the polling. @stevkan will follow up.

from botframework-directlinejs.

stevkan avatar stevkan commented on July 19, 2024

@rainmakerho, I was just revisiting this thread and it looks like a message I posted sometime ago never actually posted. Please accept my apology for the delay in response.

As was mentioned above, DirectLineJS doesn't have an ability to pause polling, at this time. It'm listing it as a bug, but there is no ETA on when a solution might become available.

from botframework-directlinejs.

compulim avatar compulim commented on July 19, 2024

Transferring this one from Web Chat to DirectLineJS.

from botframework-directlinejs.

compulim avatar compulim commented on July 19, 2024

Marking as dupe of #124 and resolving it over that uber-bug.

from botframework-directlinejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.