Skip to content

Latest commit

 

History

History
 
 

61.facebook-adapter

Facebook Adapter

Bot Framework v4 echo bot using facebook Adapter sample.

This bot has been created using Bot Framework, it shows how to create a simple echo bot that connects with Facebook to respond to messages.

Prerequisites

  • .NET Core SDK version 3.1

    # determine dotnet version
    dotnet --version

To try this sample

  • Clone the repository

     git clone https://github.com/Microsoft/BotBuilder-Samples.git
  • Connect the bot with Facebook by following the instructions below.

  • Run the bot from a terminal or from Visual Studio:

    A) From a terminal, navigate to BotBuilder-Samples/samples/csharp_dotnetcore/61.facebook-adapter

    # run the bot
    dotnet run

    B) Or from Visual Studio

    • Launch Visual Studio
    • File -> Open -> Project/Solution
    • Navigate to BotBuilder-Samples/samples/csharp_dotnetcore/61.facebook-adapter folder
    • Select FacebookAdapterBot.csproj file
    • Press F5 to run the project

Connect the bot with Facebook

Populate settings for Facebook App secret, Access Token and Verify Token in appsettings.json file.

Instructions about how to create / configure a Facebook App for your bot and where to obtain the values for the settings can be found in the documentation covering connecting a bot to Facebook using the Facebook adapter.

{
  "FacebookVerifyToken": "",
  "FacebookAppSecret": "",
  "FacebookAccessToken": ""
}

Deploy the bot to Azure

To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.

Testing your bot

You can test your bot is connected to Facebook correctly by sending a message via the Facebook Page you associated with your new Facebook App.

  1. Navigate to your Facebook Page.

  2. Click Add a Button button.

Add a button

  1. Select Contact You and Send Message and click Next.

Button settings

  1. When asked Where would you like this button to send people to? select Messenger and click Finish.

Button settings

  1. Hover over the new Send Message button that is now shown on your Facebook Page and clikc Test Button from the popup menu. This will start a new conversation with your app via Facebook Messenger, which you can use to test messaging your bot. Once the message is receieved by your bot it will send a message back to you, echoing the text from your message.

Further reading