Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Ezequiel Jadib 6b3df2c0b3
Update documentation links to point to new docs (#118)
6 years ago
..
74eb448cde
[Node] Update Emulator screenshots
7 years ago
5681fda962
ChannelData - move defaultDialog to bot constructor
7 years ago
6b3df2c0b3
Update documentation links to point to new docs (#118)
6 years ago
5681fda962
ChannelData - move defaultDialog to bot constructor
7 years ago
a2a0e1baa1
update azuredeploy.json paths
7 years ago
3b8f26a2fb
Node - Samples ES5 compliant
7 years ago
28d163ecf6
[Node] Update to botbuilder 3.7.0 (#50)
7 years ago

README.md

You have to be logged in to leave a comment. Sign In

ChannelData Bot Sample

A sample bot sending native metadata to Facebook using ChannelData.

Deploy to Azure

Prerequisites

The minimum prerequisites to run this sample are:

Code Highlights

Many messaging channels provide the ability to attach richer objects. Bot Builder lets you express these attachments in a cross channel way and connectors will do their best to render the attachments using the channels native constructs.

If you want to be able to take advantage of special features or concepts for a channel we provide a way for you to send native metadata to that channel giving you much deeper control over how your bot interacts on a channel. The way you do this is to pass extra properties via the Message.sourceEvent method.

NOTE: You do not need to use this feature unless you feel the need to access functionality not provided by the normal Activity.

The Facebook adapter supports sending full attachments via the sourceEvent method. This allows you to do anything natively that Facebook supports via the attachment schema, such as Send a check-in reminder message. Check out app.js where a new AirlineCheckin instance is send to the Facebook API using the channel's native construct.

var checkin = new FacebookDataModels.AirlineCheckin(
    'Check-in is available now',
    'en_US',
    'ABCDED',
    'http://www.airline.com/check_in',
    [
        new FacebookDataModels.FlightInfo(
            'F001',
            new FacebookDataModels.Airport(
                'SFO',
                'San Francisco',
                'T4',
                'G8'
            ),
            new FacebookDataModels.Airport(
                'EZE',
                'Buenos Aires',
                'C',
                'A2'
            ),
            new FacebookDataModels.FlightSchedule(
                now.addDays(1),
                now.addDays(1).addHours(1.5),
                now.addDays(2)
            ))
    ]);

Alternativly, you can provide JSON object instead of using the AirlineCheckin object.

var checkin = {
    "type": "template",
    "payload": {
        "template_type": "airline_checkin",
        "intro_message": "Check-in is available now",
        "locale": "en_US",
        "pnr_number": "ABCDED",
        "checkin_url": "http://www.airline.com/check_in",
        "flight_info": [
            {
                "flight_number": "F001",
                "departure_airport": {
                    "airport_code": "SFO",
                    "city": "San Francisco",
                    "terminal": "T4",
                    "gate": "G8"
                },
                "arrival_airport": {
                    "airport_code": "EZE",
                    "city": "Buenos Aires",
                    "terminal": "C",
                    "gate": "A2"
                },
                "flight_schedule": {
                    "boarding_time": formatDate(now.addDays(1)),
                    "departure_time": formatDate(now.addDays(1).addHours(1.5)),
                    "arrival_time": formatDate(now.addDays(2))
                }
            }
        ]
    }
};

Because sourceEvent accepts any object, it will hold any custom model we pass to it. In this sample, all Models classes were built to match "attachment" JSON Schema described in the Facebook's Send API Reference. Additionally, the sample includes a little logic to render the attachment appropriately for different channels.

var reply = new builder.Message(session);
if (session.message.address.channelId === 'facebook') {
    reply.sourceEvent({
        facebook: {
            attachment: checkin
        }
    });
} else {
    reply.text(checkin.toString());
}

session.send(reply);

Outcome

You will see the following in the Bot Framework Emulator when opening and running the sample solution.

Sample Outcome Emulator

On the other hand, you will see the following in your Facebook Messenger.

Sample Outcome Facebook

More Information

To get more information about how to get started in Bot Builder for Node and Attachments please review the following resources:

Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...