2

I'm trying to stablish a connection between a User and an Agent. But I need to hide an input message while sending it from the back to the bot.

I'm able to connect to the same conversation and "stop" the bot and use it to send the messages of the Agent. So at the right side is the text of the User and in the left is the text of the Agent (through the bot).

I have two webchats, one for the Agent and one for the User.

I use this code in the webchat of the User:

const store =  window.WebChat.createStore(
   {},
   ({ dispatch}) => next => action => {
      if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
        const { activity } = action.payload;
        if (activity.from.id === "Agent") {
          activity.text = "";
          action.payload = activity;
        }
        return next(action)
      }
      return next(action)
    }
  );

But the problem is in the Agent's webchat. I don't know how to hide an input message, so right now in the Agent's webchat I see the agent message duplicated.

In the user Webchat is resolved.

But in the Agent I would like to be the same:


                                             User: Hi
Bot(Agent): How can i help you?

Right now in my agents webchat is like this:


                                     User: Hi
                                     Agent: How can I help you?
Bot(Agent): How can i help you?

Solution:

if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
  dispatch({
    type: 'WEB_CHAT/SEND_MESSAGE_BACK',
    payload: {
      text: action.payload.text
    }
  });
  action.payload.text = "";
}

It's about sending the message with SEND_MESSAGE_BACK in the SEND_MESSAGE type and put action.payload.text empty so the actions of type SEND_MESSAGE and POSTBACK doesn't print anything at the right side.

DavidCG
  • 141
  • 1
  • 1
  • 10
  • I think I solved the problem. I post the solution at the end of the post. – DavidCG Jun 18 '19 at 16:31
  • Are you using one direct line endpoint and token for both web chants or an individual endpoint / token for each? If you are using one endpoint / token for both, that would explain the replication issue. – Steven Kanberg Jun 21 '19 at 21:27

0 Answers0