Botframework samples

Botframework samples DEFAULT

Sample bots and components for Composer

Composer provides bot and component samples on github at this location: composer samples, where you find C# and JavaScript samples. Specifically, the bot samples are in the folder and the component samples are in the folder. For more information about components, see Extending your bot with code.

Open a v2 sample

  1. Clone the Bot Builder samples github repository on your machine.

  2. In Composer, open one of the sample bots, such as the echo bot project.

    • The relative path to the C# sample is .
    • The relative path to the JavaScript sample is .
  3. In the left pane, select the trigger.

    echo bot greeting trigger

  4. In the upper right, select Restart bot.

  5. In the drop-down menu, select Open Web Chat. The bot displays a greeting message.

  6. In the message box enter hello. The bot will echo it back.

    echo bot hello

Composer currently provides eleven bot samples with different specialties. These samples are a good resource to learn how to build your own bot using Composer. You can use the samples and learn how to send text messages, how to ask questions, and how to control conversation flow, etc.

Below is a table of the eleven bot samples in Composer and their respective descriptions.

SampleDescription
Echo BotA bot that echoes whatever message the user enters.
Empty BotA basic bot that is ready for your creativity.
Simple TodoA sample bot that shows how to use Regex recognizer to define intents and allows you to add, list and remove items.
Todo with LUISA sample bot that shows how to use LUIS recognizer to define intents and allows you to add, list and remove items. A LUIS authoring key is required to run this sample.
Asking QuestionsA sample bot that shows how to prompt user for different types of input.
Controlling Conversation FlowA sample bot that shows how to use branching actions to control a conversation flow.
Dialog ActionsA sample bot that shows how to use actions in Composer (does not include Ask a question actions already covered in the Asking Questions example).
InterruptionsA sample bot that shows how to handle interruptions in a conversation flow. A LUIS authoring key are required to run this sample.
QnA Maker and LUISA sample bot that shows how to use both QnA Maker and LUIS. A LUIS authoring key and a QnA Knowledge Base is required to run this sample.
QnA SampleA sample bot that is provisioned to enable users to create QnA Maker knowledge base in Composer.
Responding with CardsA sample bot that shows how to send different cards using language generation.
Responding with TextA sample bot that shows how to send different text messages to users using language generation.

Open a v1 sample

The Examples can be found on the right side of the Composer home page.

To open a bot sample from Composer follow the steps:

  1. Select the sample you want to open from the Examples list.

    samples list

  2. In the Create a bot project form:

    define conversation objective

    1. Name: You can use the default name provided or enter a new name here.
    2. Description (optional): Descriptive text to describe the bot you are creating.
    3. Location: The location your bot source code files will be saved to.
  3. After you select OK in the Create a bot project form, the new bot based off the example bot you selected will open in Composer.

    ask question sample

    Note

    When you select a bot from the Examples list, a copy of the original sample is created in the Location you specify in the Create a bot project form. Any changes you make to that bot will be saved without affecting the original example. You can create as many bots based off the examples as you want, without impacting the original examples and you are free to modify and use them as a starting point when creating your own bots.

  4. Select the Start all bots button located on the Composer toolbar, then select Test in Emulator to test your new bot in the Bot Framework Emulator.

    ask question sample test

Next steps

Sours: https://docs.microsoft.com/en-us/composer/how-to-use-samples

How to use botframework-schema

Best JavaScript code snippets using botframework-schema(Showing top 8 results out of 315)

server.post(routePath, (req, res) => { this.adapter.processActivity(req, res, async (context) => { if (context.activity.type === ActivityTypes.Message) { try { const input = { message: context.activity.text, channel: `msbf-${context.activity.channelId}`, app: this.container.name, msbfContext: context,
server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { if (context.activity.type === ActivityTypes.Invoke) await messageExtension.run(context); elseawait bot.run(context); }); });
async handleTeamsMessagingExtensionSelectItem(context, obj) { const { title, text, images } = obj return { composeExtension: { type: 'result', attachmentLayout: 'list', attachments: [CardFactory.thumbnailCard(title, text, images)] } }; }
constructor() { super(); this.onMessage(async (context, next) => { TurnContext.removeRecipientMention(context.activity); const text = context.activity.text.trim().toLocaleLowerCase(); await context.sendActivity('You said ' + text); }); }
async interrupt(innerDc) { if (innerDc.context.activity.type === ActivityTypes.Message) { const text = innerDc.context.activity.text.toLowerCase(); if (text === 'logout') { const botAdapter = innerDc.context.adapter; await botAdapter.signOutUser(innerDc.context, this.connectionName); await innerDc.context.sendActivity('You have been signed out.'); returnawait innerDc.cancelAllDialogs(); } } }
constructor(conversationState, userState, dialog) { super(conversationState, userState, dialog); this.onMembersAdded(async (context, next) => { const membersAdded = context.activity.membersAdded; for (let cnt = 0; cnt < membersAdded.length; cnt++) { if (membersAdded[cnt].id !== context.activity.recipient.id) { await context.sendActivity('Welcome to TeamsBot. Type anything to get logged in. Type \'logout\' to sign-out.'); } } await next(); }); }
let text = faker.lorem.paragraph(); let images = [`${randomImageUrl}?random=${i}`] let thumbnailCard = CardFactory.thumbnailCard(title, text, images) let preview = CardFactory.thumbnailCard(title, text, images) preview.content.tap = { type: 'invoke', value: { title, text, images } }; var attachment = { ...thumbnailCard, preview } attachments.push(attachment);
if (turnContext.activity.type === ActivityTypes.Message) { turnContext.activity.type === ActivityTypes.ConversationUpdate) {
Sours: https://www.tabnine.com/code/javascript/modules/botframework-schema
  1. Wow classic intellect
  2. 17 bandsaw
  3. Android pie lg v20

Create a bot with the Bot Framework SDK

  • 11 minutes to read

APPLIES TO: SDK v4

In this quickstart, you'll learn how to build your first bot with the Bot Framework SDK for C#, Java, JavaScript or Python, and how to test your bot with the Bot Framework Emulator.

Creating your first bot doesn't require an Azure subscription or an Azure Bot Service resource. This quickstart focuses on creating your first bot locally. If you'd like to learn how to create a bot in Azure, see Create an Azure Bot resource.

Prerequisites

Templates

To add the bot templates to Visual Studio, download and install the Bot Framework v4 SDK Templates for Visual Studio VSIX file.

Note

The VSIX package includes both .NET Core 2.1 and .NET Core 3.1 versions of the C# templates. When creating new bots in Visual Studio 2019 or later, you should use the .NET Core 3.1 templates. The current bot samples use .NET Core 3.1 templates. You can find the samples that use .NET Core 2.1 templates in the 4.7-archive branch of the BotBuilder-Samples repository.

To install the templates in Visual Studio, in the top menu bar, navigate to Extensions > Manage Extensions. Then search for and install Bot Framework v4 SDK for Visual Studio.

For information about deploying .NET Core 3.1 bots to Azure, see how to deploy your bot to Azure.

.NET Core Templates will help you to quickly build new conversational AI bots using Bot Framework v4. As of May 2020, these templates and the code they generate require .NET Core 3.1.

To install the Bot Framework templates:

  1. Open a console window.

  2. Download and install .NET Core SDK download version 3.1 or later.

  3. You can use this command to determine which version of the .NET Core command-line interface you have installed.

  4. Install the three Bot Framework C# templates: the echo, core, and empty bot templates.

  5. Verify the templates have been installed correctly.

Note

The above installation steps will install all three Bot Framework templates. You don't need to install all the templates and can install just the ones you will use. This article makes use of the echo bot template.

Templates

Use the Yeoman generator to quickly set up a conversational AI bot using core AI capabilities in the Bot Framework v4. For more information, see yeoman.io.

The generator supports three different template options as shown below.

TemplateDescription
Echo BotA good template if you want a little more than "Hello World!", but not much more. This template handles the very basics of sending messages to a bot, and having the bot process the messages by repeating them back to the user. This template produces a bot that simply "echoes" back to the user anything the user says to the bot.
Empty BotA good template if you are familiar with Bot Framework v4, and simply want a basic skeleton project. Also a good option if you want to take sample code from the documentation and paste it into a minimal bot in order to learn.
Core BotA good template if you want to create advanced bots, as it uses multi-turn dialogs and LUIS, an AI based cognitive service, to implement language understanding. This template creates a bot that can extract places and dates to book a flight.

Install Yeoman

  1. Assure that you have installed node.js version 12.10 or later.

  2. Install latest npm.

  3. Install Yeoman. Make sure to install globally.

  4. Install generator-botbuilder-java. Make sure to install globally.

  5. Verify that Yeoman and generator-botbuilder-java have been installed correctly.

Templates

To install Yeoman and the Yeoman generator for Bot Framework v4:

  1. Open a terminal or elevated command prompt.

  2. Switch to the directory for your JavaScript bots. Create it first if you don't already have one.

  3. Make sure you have the latest versions of npm and Yeoman.

  4. Install the Yeoman generator. Yeoman is a tool for creating applications. For more information, see yeoman.io.

    Note

    The install of Windows build tools listed below is only required if you use Windows as your development operating system. For some installations, the install step for restify is giving an error related to . If this is the case you can try running this command with elevated permissions. This call may also hang without exiting if Python is already installed on your system:

    Only run this command if you are on Windows.

Create and enable a virtual environment

A virtual environment is a combination of a specific Python interpreter and libraries that are different from your global settings. The virtual environment is specific to a project and is maintained in the project folder. A benefit to using a virtual environment is that as you develop a project over time, the virtual environment always reflects the project's exact dependencies. To learn more about virtual environments, see Creation of virtual environments.

Navigate to the directory where you want to create your bot. Then run the following commands for your preferred platform. After you activate your virtual environment, your command line/terminal should be prefaced with . This lets you know that the virtual environment is active. You can deactivate your virtual environment at any time by typing: .

macOS/Linux

Windows

Templates

Install the necessary packages by running the following commands:

Important

If you're using a 32-bit version of Python, make sure you also run .

Create a bot

In Visual Studio, create a new bot project using the Echo Bot (Bot Framework v4 - .NET Core 3.1) template. Choose AI Bots from the project types to show only bot templates.

Visual Studio create a new project dialog

Thanks to the template, your project contains all the code that's necessary to create the bot in this quickstart. You don't need any additional code to test your bot.

Note

If you create a Core bot, you'll need a LUIS language model. You can create a language model at luis.ai. After creating the model, update the configuration file.

Make sure that .NET Core 3.1 is installed.

  1. In Visual Studio Code, open a new terminal window.

  2. Navigate to the directory in which you want to create your bot project.

  3. Create a new echo bot project using the following command. Replace with the name to use for your bot project.

  1. Open a new terminal window.

  2. Navigate to the directory in which you want to create your bot project.

  3. Create a new echo bot project using the following command. Replace with the name to use for your bot project.

Run the following command to create an echo bot from templates. The command uses default options for its parameters.

Yeoman prompts you for some information with which to create your bot. For this tutorial, use the default values.

The generator supports a number of command line options that can be used to change the generator's default options or to pre-seed a prompt. The options are case-sensitive.

Command line OptionDescription
List help text for all supported command-line options
The name given to the bot project
The Java package name to use for the bot
The template used to generate the project. Options are , , or . See https://github.com/Microsoft/BotBuilder-Samples/tree/master/generators/generator-botbuilder for additional information regarding the different template options and their functional differences.
The generator will not prompt for confirmation before creating a new bot. Any requirement options not passed on the command line will use a reasonable default value. This option is intended to enable automated bot generation for testing purposes.

Thanks to the template, your project contains all the code that's necessary to create the bot in this quickstart. You don't need any additional code to test your bot.

Note

If you create a bot, you'll need a LUIS language model. You can create a language model at luis.ai. After creating the model, update the configuration file.

  1. Use the generator to create an echo bot.

    Yeoman prompts you for some information with which to create your bot. For this tutorial, use the default values.

Thanks to the template, your project contains all the code that's necessary to create the bot in this quickstart. You don't need any additional code to test your bot.

Note

If you create a bot, you'll need a LUIS language model. You can create a language model at luis.ai. After creating the model, update the configuration file.

  1. From your working directory, run the following command to download the echo bot template and its dependencies:

  2. You'll be prompted to give your bot a name and description. Enter the following values:

    • bot_name: echo_bot
    • bot_description: A bot that echoes back user response.

    Set Python bot name and description

Start your bot

In Visual Studio

  1. Open your bot project.
  2. Run the project without debugging.

This will build the application, deploy it to localhost, and launch the web browser to display the application's page. At this point, your bot is running locally on port 3978.

To run your bot from VS Code:

  1. Open your bot project folder.

    If you're prompted to select a project, select the one for the bot you just created.

  2. Go to Run, and then select Run Without Debugging.

    vsc run

    • Select the .Net Core environment.

    vsc env

    • If this command updated your launch settings, save the changes and rerun the command.

This will build the application, deploy it to localhost, and launch the web browser to display the application's page. At this point, your bot is running locally on port 3978.

To run your bot locally in a command prompt or terminal:

  1. Change directories to the project folder for your bot.

  2. Use to start the bot.

This will build the application and deploy it to localhost. The application's default web page will not display, but at this point, your bot is running locally on port 3978.

  1. From a terminal, navigate to the directory where you saved your bot, then execute the commands listed below.

  2. Build the Maven project and packages it into a .jar file (archive).

  3. Run the bot locally. Replace the archive-name with the actual name from the previous command.

You are now ready to start the Emulator.

In a terminal or command prompt change directories to the one created for your bot, and start it with .

At this point, your bot is running locally on port 3978.

  1. From the command line/terminal, change directories to .

  2. Install the dependencies for the echo bot template.

  3. After the dependencies are installed, run the following command to start your bot:

    You will know your bot is ready to test when you see the last line shown in the screenshot below:

    Python bot running locally

  4. Copy the http address in the last line. You will need it when you use the Emulator to interact with your bot.

Start the Emulator and connect your bot

  1. Start the Bot Framework Emulator.

  2. Select Open Bot on the Emulator's Welcome tab.

  3. Enter your bot's URL, which is your local host and port, with added to the path. The address is usually: .

    open a bot

  4. Then select Connect.

    Send a message to your bot, and the bot will respond back.

    echo message

Additional Resources

  • See Debug a bot for how to debug using Visual Studio or Visual Studio Code and the Bot Framework Emulator.
  • See Tunneling (ngrok) for information on how to install ngrok.

Next steps

Feedback

View all page feedback

Sours: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-quickstart-create-bot
Ben Brown explains how he built a Weather Bot with Composer

Bot Framework Samples

Click here to find out what's new with Bot Framework

Overview

This branch contains samples for the released version of the Microsoft Bot Framework V4 SDK for .NET, JS and Python. If you need samples for the Bot Framework V3 SDK, go here.

Getting the samples

To use the samples, clone this GitHub repository using Git.

git clone https://github.com/Microsoft/BotBuilder-Samples.git cd BotBuilder-Samples

Sample lists

Samples are designed to illustrate functionality you'll need to implement to build great bots!

Bot essentials

Sample NameDescription.NETJavaScriptPythonJava
2Echo botDemonstrates how to receive and send messages..NET CoreJavaScript, TypeScriptPythonJava
3Welcome userIntroduces activity types and provides a welcome message on conversation update activity..NET CoreJavaScript, TypeScriptPythonJava
5Multi turn promptsDemonstrates how to use waterfall dialog, prompts, and component dialog to create a simple interaction that asks the user for name, age, and prints back that information..NET CoreJavaScript, TypeScriptPythonJava
6Using cardsIntroduces all card types including thumbnail, audio, media etc. Builds on Welcoming user + multi-prompt bot by presenting a card with buttons in welcome message that route to appropriate dialog..NET CoreJavaScript, TypeScriptPythonJava
7Adaptive cardsDemonstrates how the multi-turn dialog can use a card to get user input for name and age..NET CoreJavaScriptPythonJava
8Suggested actionsDemonstrates how to enable your bot to present buttons that the user can tap to provide input..NET CoreJavaScriptPythonJava
13Core botCore bot shows how to use cards, dialog, and Language Understanding (LUIS)..NET Core, .NET WebJavaScript, TypeScriptPythonJava
14NLP with dispatchDemonstrates how to dispatch across LUIS and QnA Maker..NET CoreJavaScriptPythonJava
15Handling attachmentsDemonstrates how to listen for/handle user provided attachments..NET CoreJavaScriptPythonJava
40TIMEX resolutionDemonstrates various ways to parse and manipulate the TIMEX expressions you get from LUIS and the DateTimeRecognizer used by the DateTimePrompt..NET CoreJavaScriptPythonJava
43Complex dialogsDemonstrates different ways for composing dialogs..NET CoreJavaScriptPythonJava
45State managementDemonstrates how to use state management and storage objects to manage and persist state..NET CoreJavaScriptPythonJava

Advanced bots

Sample NameDescription.NETJavaScriptPythonJava
1Console echo botIntroduces the concept of adapter and demonstrates a simple echo bot on console adapter and how to send a reply and access the incoming message..NET CoreJavaScript, TypeScriptPython
1Browser echo botDemonstrates how to host a bot in the browser using Web Chat and a custom Web Chat Adapter.ECMAScript 6
16Proactive messagesDemonstrates how to send proactive messages to users..NET CoreJavaScript, TypeScriptPythonJava
17Multilingual botUsing translate middleware to support a multi-lingual bot. Demonstrates custom middleware..NET CoreJavaScriptPythonJava
19Custom dialogsDemonstrates complex conversation flow using the Dialogs library..NET CoreJavaScriptPythonJava
21Application InsightsDemonstrates how to add telemetry logging to your bot, storing telemetry within Application Insights..NET CoreJavaScriptJava
23Facebook eventsIntegrate and consume Facebook specific payloads, such as post-backs, quick replies and opt-in events..NET CoreJavaScriptPythonJava
42Scale outDemonstrates how you can build your own state solution from the ground up that supports scaled out deployment with ETag based optimistic locking..NET CorePythonJava
44Basic custom promptsDemonstrates how to implement your own basic prompts to ask the user for information..NET CoreJavaScriptPythonJava
47Inspection middlewareDemonstrates how to use middleware to allow the Bot Framework Emulator to debug traffic into and out of the bot in addition to looking at the current state of the bot..NET CoreJavaScriptPythonJava
70Styling webchatThis sample shows how to create a web page with custom Web Chat component.ECMAScript 6

Authentication samples

Sample NameDescription.NETJavaScriptPythonJava
18OAuth authenticationBot that demonstrates how to integrate OAuth providers..NET CoreJavaScriptPythonJava
24MSGraph authenticationDemonstrates bot authentication capabilities of Azure Bot Service. Demonstrates utilizing the Microsoft Graph API to retrieve data about the user..NET CoreJavaScriptPythonJava
46Teams authenticationDemonstrates how to use authentication for a bot running in Microsoft Teams..NET CoreJavaScriptPythonJava

QnA Maker samples

Sample NameDescription.NETJavaScriptPythonJava
11QnA Maker (simple)Demonstrates how to use QnA Maker to have simple single-turn conversations.NET CoreJavaScriptPythonJava
49QnA Maker (advanced)Demonstrates how to integrate Multiturn and Active learning in a QnA Maker bot. This also demonstrates the QnAMakerDialog class..NET CoreJavaScriptJava

Teams samples

Sample NameDescription.NETJavaScriptPythonJava
25Message ReactionsDemonstrates how to create a simple bot that responds to Message Reactions.NET CoreJavaScriptJava
46AuthenticationDemonstrates how to use authentication for a bot running in Microsoft Teams..NET CoreJavaScriptPythonJava
50Messaging extensions - searchA Messaging Extension that accepts search requests and returns results..NET CoreJavaScriptPythonJava
51Messaging extensions - actionA Messaging Extension that accepts parameters and returns a card. Also, how to receive a forwarded message as a parameter in a Messaging Extension..NET CoreJavaScriptPythonJava
52Messaging extensions - auth and configA Messaging Extension that has a configuration page, accepts search requests and returns results after the user has signed in..NET CoreJavaScriptJava
53Messaging extensions - action previewDemonstrates how to create a Preview and Edit flow for a Messaging Extension..NET CoreJavaScriptPythonJava
54Task moduleDemonstrates how to retrieve a Task Module, and values from cards in the Task Module, for a Messaging Extension..NET CoreJavaScriptPythonJava
55Link unfurlingA Messaging Extension that performs link unfurling..NET CoreJavaScriptPythonJava
56File uploadDemonstrates how to obtain file consent, and upload files to Teams from a bot. Also, how to receive a file sent to a bot..NET CoreJavaScriptPythonJava
57Conversation botDemonstrates various features of bots on Teams: message all members in a Team or Channel, @mention a user from a bot, update previously sent messages, etc..NET CoreJavaScriptPythonJava
58Start new thread in a channelDemonstrates creating a new thread in a channel..NET CoreJavaScriptPythonJava

Custom adapter samples

Sample NameDescription.NETJavaScriptPythonJava
60SlackDemonstrates the use of the custom adapter for Slack..NET CorePython
61FacebookDemonstrates the use of the custom adapter for Facebook..NET Core
62WebexDemonstrates the use of the custom adapter for Webex Teams..NET Core
63TwilioDemonstrates the use of the custom adapter for Twilio..NET Core

Skills samples

Sample NameDescription.NETJavaScriptPythonJava
80Skills - simple bot to botThis sample shows how to connect a skill to a skill consumer..NET CoreJavaScriptPythonJava
81Skills - skill dialogThis sample shows how to connect a skill to a skill dialog consumer..NET CoreJavaScriptPythonJava

Experimental / preview samples

A collection of experimental samples exist, intended to provide samples for features currently in preview or as a way to solicit feedback on a given design, approach, or technology being considered by the Bot Framework Team.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Reporting security issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [email protected] You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

Copyright (c) Microsoft Corporation. All rights reserved.

Sours: https://github.com/microsoft/BotBuilder-Samples

Samples botframework

.

Bot Framework Composer: Bot Framework’s new collaborative Conversational AI development environment

.

Similar news:

.



109 110 111 112 113