Skip to content

Commit 37c361d

Browse files
authored
Empty bot generator (#356)
* Initial template for echo bot * Added template zip file * Added template zip file * Readme for top level generators folder * Pylint fixes for generator, readme updates * Adding empty bot generator, ported latest on_error changes * PR changes addressed
1 parent 9a547ae commit 37c361d

File tree

12 files changed

+668
-29
lines changed

12 files changed

+668
-29
lines changed

generators/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ The Core Bot template consists of set of core features most every bot is likely
3737

3838
| Core Bot Features | Description |
3939
| ------------------ | ----------- |
40-
| [Send and receive messages](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-send-messages?view=azure-bot-service-4.0&tabs=javascript) | The primary way your bot will communicate with users, and likewise receive communication, is through message activities. Some messages may simply consist of plain text, while others may contain richer content such as cards or attachments. |
41-
| [Proactive messaging](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0) using [Adaptive Cards](https://docs.microsoft.com/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0?#using-adaptive-card-greeting) | The primary goal when creating any bot is to engage your user in a meaningful conversation. One of the best ways to achieve this goal is to ensure that from the moment a user first connects to your bot, they understand your bot’s main purpose and capabilities. We refer to this as "welcoming the user." The Core template uses an [Adaptive Card](http://adaptivecards.io) to implement this behavior. |
40+
| [Send and receive messages](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-send-messages?view=azure-bot-service-4.0) | The primary way your bot will communicate with users, and likewise receive communication, is through message activities. Some messages may simply consist of plain text, while others may contain richer content such as cards or attachments. |
41+
| [Proactive messaging](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0) using [Adaptive Cards](https://docs.microsoft.com/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0?#using-adaptive-card-greeting) | The primary goal when creating any bot is to engage your user in a meaningful conversation. One of the best ways to achieve this goal is to ensure that from the moment a user first connects to your bot, they understand your bot’s main purpose and capabilities. We refer to this as "welcoming the user." The Core template uses an [Adaptive Card](http://adaptivecards.io) to implement this behavior. |
4242
| [Language understanding using LUIS](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-v4-luis?view=azure-bot-service-4.0) | The ability to understand what your user means conversationally and contextually can be a difficult task, but can provide your bot a more natural conversation feel. Language Understanding, called LUIS, enables you to do just that so that your bot can recognize the intent of user messages, allow for more natural language from your user, and better direct the conversation flow. |
4343
| [Multi-turn conversation support using Dialogs](https://docs.microsoft.com/azure/bot-service/bot-builder-concept-dialog?view=azure-bot-service-4.0) | The ability to manage conversations is an important part of the bot/user interation. Bot Framework introduces the concept of a Dialog to handle this conversational pattern. Dialog objects process inbound Activities and generate outbound responses. The business logic of the bot runs either directly or indirectly within Dialog classes. |
4444
| [Managing conversation state](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-v4-state?view=azure-bot-service-4.0) | 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. |
@@ -51,7 +51,7 @@ The Empty Bot template is the minimal skeleton code for a bot. It provides a st
5151

5252
## Features by Template
5353

54-
| Feature | Empty Bot* | Echo Bot | Core Bot* |
54+
| Feature | Empty Bot | Echo Bot | Core Bot* |
5555
| --------- | :-----: | :-----: | :-----: |
5656
| Generate code in Python | X | X | X |
5757
| Support local development and testing using the [Bot Framework Emulator v4](https://www.github.com/microsoft/botframework-emulator) | X | X | X |
@@ -64,7 +64,7 @@ The Empty Bot template is the minimal skeleton code for a bot. It provides a st
6464
| Handle user interruptions | | | X |
6565
| Unit test a bot using Bot Framework Testing framework (optional) | | | X |
6666

67-
*Empty Bot and Core Bot templates are work in progress landing soon.
67+
*Core Bot template is a work in progress landing soon.
6868
## Installation
6969

7070
1. Install [cookiecutter](https://github.com/cookiecutter/cookiecutter) using [pip](https://pip.pypa.io/en/stable/) (we assume you have pre-installed [python 3](https://www.python.org/downloads/)).
@@ -99,7 +99,7 @@ To create a Core Bot project:
9999
To create an Empty Bot project:
100100

101101
```bash
102-
# Work in progress
102+
cookiecutter https://github.com/microsoft/botbuilder-python/releases/download/Templates/empty.zip
103103
```
104104

105105
When the generator is launched, it will prompt for the information required to create a new bot.

generators/app/templates/echo/{{cookiecutter.bot_name}}/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This bot has been created using [Bot Framework](https://dev.botframework.com), i
88

99
This sample **requires** prerequisites in order to run.
1010

11-
### Install Python 3.7
11+
### Install Python 3.6
1212

1313
## Running the sample
1414
- Run `pip install -r requirements.txt` to install all dependencies
@@ -37,7 +37,6 @@ This sample **requires** prerequisites in order to run.
3737
- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0)
3838
- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
3939
- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0)
40-
- [.NET Core CLI tools](https://docs.microsoft.com/dotnet/core/tools/?tabs=netcore2x)
4140
- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest)
4241
- [Azure Portal](https://portal.azure.com)
4342
- [Language Understanding using LUIS](https://docs.microsoft.com/azure/cognitive-services/luis/)

generators/app/templates/echo/{{cookiecutter.bot_name}}/app.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
import asyncio
55
import sys
6+
from datetime import datetime
67
from types import MethodType
78

89
from flask import Flask, request, Response
910
from botbuilder.core import (
1011
BotFrameworkAdapter,
1112
BotFrameworkAdapterSettings,
12-
MessageFactory,
1313
TurnContext,
1414
)
15-
from botbuilder.schema import Activity, InputHints
15+
from botbuilder.schema import Activity, ActivityTypes
1616
from bot import MyBot
1717

1818
# Create the loop and Flask app
@@ -30,20 +30,24 @@ async def on_error(self, context: TurnContext, error: Exception):
3030
# This check writes out errors to console log .vs. app insights.
3131
# NOTE: In production environment, you should consider logging this to Azure
3232
# application insights.
33-
print(f"\n [on_turn_error]: {error}", file=sys.stderr)
33+
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
3434

3535
# Send a message to the user
36-
error_message_text = "Sorry, it looks like something went wrong."
37-
error_message = MessageFactory.text(
38-
error_message_text, error_message_text, InputHints.expecting_input
39-
)
40-
await context.send_activity(error_message)
41-
42-
# pylint: disable=protected-access
43-
if self._conversation_state:
44-
# If state was defined, cleare it.
45-
await self._conversation_state.delete(context)
46-
36+
await context.send_activity("The bot encounted an error or bug.")
37+
await context.send_activity("To continue to run this bot, please fix the bot source code.")
38+
# Send a trace activity if we're talking to the Bot Framework Emulator
39+
if context.activity.channel_id == 'emulator':
40+
# Create a trace activity that contains the error object
41+
trace_activity = Activity(
42+
label="TurnError",
43+
name="on_turn_error Trace",
44+
timestamp=datetime.utcnow(),
45+
type=ActivityTypes.trace,
46+
value=f"{error}",
47+
value_type="https://www.botframework.com/schemas/error"
48+
)
49+
# Send a trace activity, which will be displayed in Bot Framework Emulator
50+
await context.send_activity(trace_activity)
4751

4852
ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)
4953

@@ -64,12 +68,9 @@ def messages():
6468
request.headers["Authorization"] if "Authorization" in request.headers else ""
6569
)
6670

67-
async def aux_func(turn_context):
68-
await BOT.on_turn(turn_context)
69-
7071
try:
7172
task = LOOP.create_task(
72-
ADAPTER.process_activity(activity, auth_header, aux_func)
73+
ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
7374
)
7475
LOOP.run_until_complete(task)
7576
return Response(status=201)

generators/app/templates/echo/{{cookiecutter.bot_name}}/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ class DefaultConfig:
1010
PORT = 3978
1111
APP_ID = os.environ.get("MicrosoftAppId", "")
1212
APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "")
13-
LUIS_APP_ID = os.environ.get("LuisAppId", "")
14-
LUIS_API_KEY = os.environ.get("LuisAPIKey", "")
15-
# LUIS endpoint host name, ie "westus.api.cognitive.microsoft.com"
16-
LUIS_API_HOST_NAME = os.environ.get("LuisAPIHostName", "")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"bot_name": "my_chat_bot",
3+
"bot_description": "Demonstrate the core capabilities of the Microsoft Bot Framework"
4+
}

0 commit comments

Comments
 (0)