2

I've deployed a bot written in nodejs using backchannel. In my BOT, I am creating event as follows

creating event in a bot.dialog:

    var ev = createEvent('sendUserInfo', "test", session.message.address);
   session.endDialog(ev)

event function

const createEvent = (eventName, value, address) => {
var msg = new builder.Message().address(address);
msg.data.type = 'event';
msg.data.name = eventName;
msg.data.value = value;
return msg;}

In web chat javascript, I am trying to subscribe for this event, but NOT getting any response.

  botConnection.activity$
      .filter(activity => activity.type === "event")
      .subscribe(activity => console.log(activity));

Same subscription is working properly if I create postActivity from web chat directly.

   botConnection
      .postActivity({ type: "event", name: "sendUserInfo", value: "test", from: user })
      .subscribe(id => console.log("success", id));

Any suggestion, why I am not able to catch events created from BOT in web chat ?

Other way is working fine, if I create event from web chat and subscribe for event in BOT it working as expected.

bot.on("event", function (event) {
    var msg = new builder.Message().address(event.address);
    msg.data.textLocale = "en-us";
    bot.send(msg);
})
0

2 Answers 2

2

I am not very clear about your code and scenario. But I send an event in a dialog to web chat, and it is successfully captured in activity$.filer....

In Bot:

bot.dialog('/', function (session) {
    session.send('You said ' + session.message.text);
    var msg = new builder.Message(session);
    msg.data.type = 'event';
    msg.data.name = 'updateUrl';
    msg.data.value = 'hello world';
    session.send(msg);
});

in Web chat:

botConnection.activity$
      .filter(activity => {console.log('filter');console.log(activity);return activity.type === "event"})
      .subscribe((activity) => {console.log(activity)});

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I tested your code but with botConnection altered to what is shown below and it worked just fine. Make the following change and you should be good to go.

Steve.

botConnection.activity$
    .filter(function (activity) {
        return activity.type === 'event' && activity.name === 'sendUserInfo';
    })
    .subscribe(function (activity) {
        console.log(activity.name + ' received with value: ' + activity.value);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.