question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing information from the client to Composer bot

See original GitHub issue

I am trying to post a custom event via Direct Line to my Composer-based bot.

I found a page for the Bot Framework SDK v3 showing how to send a custom activity, however this page is not present in the v4 docs.

This is my code, I’m utilising the Web Chat control:

 var dl = window.WebChat.createDirectLine({
        token: '[token]'
    });
    
    window.WebChat.renderWebChat(
        {
            directLine: dl,
            userID: 'YOUR_USER_ID',
            username: 'Web Chat User',
            locale: 'en-US',
            botAvatarInitials: 'WC',
            userAvatarInitials: 'WW'
        },
        document.getElementById('webchat')
    );

    window.setTimeout(function () {
        dl.postActivity({ type: "event", value: "hello", from: { id: "me" }, name: "PageLoaded" })
            .subscribe(id => console.log("success"));
    }, 5000);

I have a 5 second delay before posting the activity to make sure everything loads.

This works in as much as that when the activity is posted, I get my welcome text back from the bot, however the custom event is never fired on the Composer side.

I created the event in Composer by

  1. Adding a new Trigger
  2. Selected Custom events and provided the name PageLoaded
  3. Added “Send a response” to say “Got page loaded event”

I need to know how to be able to pull the value from the event, in this case the value “hello”.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
benjaminsommerfeldcommented, Oct 26, 2020

@knightmeister Maybe this can help you, we are sending an activity event from Webchat to Composer like this:

        const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
            if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
                dispatch({
                    type: 'WEB_CHAT/SEND_EVENT',
                    payload: {
                        name: 'loginevent',
                        value: { prename: 'Stefan', surname:'Lauf' }
                    }
                });
            }

            return next(action);
        });

window.WebChat.renderWebChat( { directLine: window.WebChat.createDirectLine({ token }), store }, document.getElementById(‘webchat’) );

—> when loading this webchat html page, it directly sends the “loginevent” in store.

The webchat code is inspired by this sample: https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/a.welcome-event

The composer then receives it with an “Activity Event” trigger

Screenshot 2020-10-26 at 12 23 44

Screenshot 2020-10-26 at 12 24 36

This way it works for us. Hope this can help you.

0reactions
knightmeistercommented, Oct 28, 2020

Many thanks @benjaminsommerfeld, this allowed me to determine where I was wrong. My JavaScript works, but the issue was I was using a dialog event, rather than an activity event.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass information from client to bot framework ...
I'm able to get email id and name through direct line token generation api, I also need to capture some additional information from...
Read more >
Make an HTTP request from Bot Framework Composer
Learn how to make an HTTP request to access an external service, on behalf of the user or as part of your business...
Read more >
Using Bot Framework Composer to pass variables back to ...
Using Bot Framework Composer to pass variables back to Power Virtual Agents · 1 - Use Case · 2 - Install Microsoft Bot...
Read more >
Communicate with External Systems - Anthology Inc.
You can use Bot Framework Composer to call the API of another system, retrieve data through an HTTP request, and then show the...
Read more >
Events - Microsoft Open Source
Event Activities are used to pass metadata between a bot and user without being visible to the user. The data from these activities...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found