Skip to content

Latest commit

 

History

History
 
 

02.b.echobot-with-counter

echobot-with-counter

Bot Framework v4 echobot with counter sample

This bot has been created using Microsoft Bot Framework, it shows how to create a simple bot with state. The bot maintains a simple counter that increases with each message from the user.

Prerequisites

  • Node.js version 8.5 or higher
    # determine node version
    node --version

To try this sample

  • Clone the repository
    git clone https://github.com/microsoft/botbuilder-samples.git
  • In a terminal, navigate to samples/javascript_nodejs/02.b.echobot-with-counter
    cd samples/javascript_nodejs/02.b.echobot-with-counter
  • Install modules
    npm install
  • Start the bot
    npm start

Testing the bot using Bot Framework Emulator v4

Microsoft Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.

  • Install the Bot Framework Emulator version 4.2.0 or greater from here

Connect to the bot using Bot Framework Emulator v4

  • Launch Bot Framework Emulator
  • File -> Open Bot Configuration
  • Navigate to samples/javascript_nodejs/02.echobot-with-state folder
  • Select echobot-with-counter.bot file

Bot state

A key to good bot design is to track the context of a conversation, so that your bot remembers things like the answers to previous questions. Depending on what your bot is used for, you may even need to keep track of conversation state or store user related information for longer than the lifetime of one given conversation.

In this example, the bot's state is used to track number of messages.

A bot's state is information it remembers in order to respond appropriately to incoming messages. The Bot Builder SDK provides classes for storing and retrieving state data as an object associated with a user or a conversation.

- Conversation properties help your bot keep track of the current conversation the bot is having with the user. If your bot needs to complete a sequence of steps or switch between conversation topics, you can use conversation properties to manage steps in a sequence or track the current topic. Since conversation properties reflect the state of the current conversation, you typically clear them at the end of a session, when the bot receives an end of conversation activity.

- User properties can be used for many purposes, such as determining where the user's prior conversation left off or simply greeting a returning user by name. If you store a user's preferences, you can use that information to customize the conversation the next time you chat. For example, you might alert the user to a news article about a topic that interests her, or alert a user when an appointment becomes available. You should clear them if the bot receives a delete user data activity.

Deploy the bot to Azure

Prerequisites

Provision a Bot with Azure Bot Service

After creating the bot and testing it locally, you can deploy it to Azure to make it accessible from anywhere. To deploy your bot to Azure:

# login to Azure
az login
# set you Azure subscription
az account set --subscription "<azure-subscription>"
# provision Azure Bot Services resources to host your bot
msbot clone services --name "<your_bot_name>" --code-dir "." --location westus --sdkLanguage "Node" --folder deploymentScripts/msbotClone --verbose

Publishing Changes to Azure Bot Service

As you make changes to your bot running locally, and want to deploy those change to Azure Bot Service, you can publish those change using either publish.cmd if you are on Windows or ./publish if you are on a non-Windows platform. The following is an example of publishing

# run the publish helper (non-Windows) to update Azure Bot Service.  Use publish.cmd if running on Windows
./publish

Getting Additional Help Deploying to Azure

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

Further reading