8000 Axsuarez/generators (#354) · sherlock666/botbuilder-python@9a547ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a547ae

Browse files
authored
Axsuarez/generators (microsoft#354)
* Initial template for echo bot * Pylint fixes for generator, readme updates
1 parent e183e57 commit 9a547ae

File tree

10 files changed

+740
-8
lines changed

10 files changed

+740
-8
lines changed

generators/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Microsoft Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

generators/README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# python-generator-botbuilder
2+
3+
Cookiecutter generators for [Bot Framework v4](https://dev.botframework.com). Will let you quickly set up a conversational AI bot
4+
using core AI capabilities.
5+
6+
## About
7+
8+
`python-generator-botbuilder` will help you build new conversational AI bots using the [Bot Framework v4](https://dev.botframework.com).
9+
10+
## Templates
11+
12+
The generator supports three different template options. The table below can help guide which template is right for you.
13+
14+
| Template | Description |
15+
| ---------- | --------- |
16+
| Echo Bot | A 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. |
17+
| Core Bot | Our most advanced template, the Core template provides 6 core features every bot is likely to have. This template covers the core features of a Conversational-AI bot using [LUIS](https://www.luis.ai). See the **Core Bot Features** table below for more details. |
18+
| Empty Bot | A 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. |
19+
20+
### How to Choose a Template
21+
22+
| Template | When This Template is a Good Choice |
23+
| -------- | -------- |
24+
| Echo Bot | You are new to Bot Framework v4 and want a working bot with minimal features. |
25+
| Core Bot | You understand some of the core concepts of Bot Framework v4 and are beyond the concepts introduced in the Echo Bot template. You're familiar with or are ready to learn concepts such as language understanding using LUIS, managing multi-turn conversations with Dialogs, handling user initiated Dialog interruptions, and using Adaptive Cards to welcome your users. |
26+
| Empty Bot | You are a seasoned Bot Framework v4 developer. You've built bots before, and want the minimum skeleton of a bot. |
27+
28+
### Template Overview
29+
30+
#### Echo Bot Template
31+
32+
The Echo Bot template is slightly more than the a classic "Hello World!" example, but not by much. This template shows the basic structure of a bot, how a bot recieves messages from a user, and how a bot sends messages to a user. The bot will "echo" back to the user, what the user says to the bot. It is a good choice for first time, new to Bot Framework v4 developers.
33+
34+
#### Core Bot Template
35+
36+
The Core Bot template consists of set of core features most every bot is likely to have. Building off of the core message processing features found in the Echo Bot template, this template adds a number of more sophisticated features. The table below lists these features and provides links to additional documentation.
37+
38+
| Core Bot Features | Description |
39+
| ------------------ | ----------- |
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. |
42+
| [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. |
43+
| [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. |
44+
| [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. |
45+
| [How to handle user-initiated interruptions](https://docs.microsoft.com/azure/bot-service/bot-builder-howto-handle-user-interrupt?view=azure-bot-service-4.0) | While you may think that your users will follow your defined conversation flow step by step, chances are good that they will change their minds or ask a question in the middle of the process instead of answering the question. Handling interruptions means making sure your bot is prepared to handle situations like this. |
46+
| [How to unit test a bot](https://aka.ms/cs-unit-test-docs) | Optionally, the Core Bot template can generate corresponding unit tests that shows how to use the testing framework introduced in Bot Framework version 4.5. Selecting this option provides a complete set of units tests for Core Bot. It shows how to write unit tests to test the various features of Core Bot. To add the Core Bot unit tests, run the generator and answer `yes` when prompted. See below for an example of how to do this from the command line. |
47+
48+
#### Empty Bot Template
49+
50+
The Empty Bot template is the minimal skeleton code for a bot. It provides a stub `on_turn` handler but does not perform any actions. If you are experienced writing bots with Bot Framework v4 and want the minimum scaffolding, the Empty template is for you.
51+
52+
## Features by Template
53+
54+
| Feature | Empty Bot* | Echo Bot | Core Bot* |
55+
| --------- | :-----: | :-----: | :-----: |
56+
| Generate code in Python | X | X | X |
57+
| Support local development and testing using the [Bot Framework Emulator v4](https://www.github.com/microsoft/botframework-emulator) | X | X | X |
58+
| Core bot message processing | | X | X |
59+
| Deploy your bot to Microsoft Azure | | Pending | Pending |
60+
| Welcome new users using Adaptive Card technology | | | X |
61+
| Support AI-based greetings using [LUIS](https://www.luis.ai) | | | X |
62+
| Use Dialogs to manage more in-depth conversations | | | X |
63+
| Manage conversation state | | | X |
64+
| Handle user interruptions | | | X |
65+
| Unit test a bot using Bot Framework Testing framework (optional) | | | X |
66+
67+
*Empty Bot and Core Bot templates are work in progress landing soon.
68+
## Installation
69+
70+
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/)).
71+
72+
```bash
73+
pip install cookiecutter
74+
```
75+
76+
2. Verify that cookiecutter has been installed correctly by typing the following into your console:
77+
78+
```bash
79+
cookiecutter --help
80+
```
81+
82+
83+
## Usage
84+
85+
### Creating a New Bot Project
86+
87+
To create an Echo Bot project:
88+
89+
```bash
90+
cookiecutter https://github.com/microsoft/botbuilder-python/releases/download/Templates/echo.zip
91+
```
92+
93+
To create a Core Bot project:
94+
95+
```bash
96+
# Work in progress
97+
```
98+
99+
To create an Empty Bot project:
100+
101+
```bash
102+
# Work in progress
103+
```
104+
105+
When the generator is launched, it will prompt for the information required to create a new bot.
106+
107+
### Generator Command Line Options and Arguments
108+
109+
Cookiecutter supports a set of pre-defined command line options, the complete list with descriptions is available [here](https://cookiecutter.readthedocs.io/en/0.9.1/advanced_usage.html#command-line-options).
110+
111+
Each generator can recieve a series of named arguments to pre-seed the prompt default value. If the `--no-input` option flag is send, these named arguments will be the default values for the template.
112+
113+
| Named argument | Description |
114+
| ------------------- | ----------- |
115+
| project_name | The name given to the bot project |
116+
| bot_description | A brief bit of text that describes the purpose of the bot |
117+
| add_tests | **PENDING** _A Core Bot Template Only Feature_. The generator will add unit tests to the Core Bot generated bot. This option is not available to other templates at this time. To learn more about the test framework released with Bot Framework v4.5, see [How to unit test bots](https://aka.ms/js-unit-test-docs). This option is intended to enable automated bot generation for testing purposes. |
118+
119+
#### Example Using Named Arguments
120+
121+
This example shows how to pass named arguments to the generator, setting the default bot name to test_project.
122+
123+
```bash
124+
# Run the generator defaulting the bot name to test_project
125+
cookiecutter https://github.com/microsoft/botbuilder-python/releases/download/Templates/echo.zip project_name="test_project"
126+
```
127+
128+
### Generating a Bot Using --no-input
129+
130+
The generator can be run in `--no-input` mode, which can be used for automated bot creation. When run in `--no-input` mode, the generator can be configured using named arguments as documented above. If a named argument is ommitted a reasonable default will be used.
131+
132+
#### Default Values
133+
134+
| Named argument | Default Value |
135+
| ------------------- | ----------- |
136+
| bot_name | `my-chat-bot` |
137+
| bot_description | "Demonstrate the core capabilities of the Microsoft Bot Framework" |
138+
| add_tests | `False`|
139+
140+
#### Examples Using --no-input
141+
142+
This example shows how to run the generator in --no-input mode, setting all required options on the command line.
143+
144+
```bash
145+
# Run the generator, setting all command line options
146+
cookiecutter https://github.com/microsoft/botbuilder-python/releases/download/Templates/echo.zip --no-input project_name="test_bot" bot_description="Test description"
147+
```
148+
149+
This example shows how to run the generator in --no-input mode, using all the default command line options. The generator will create a bot project using all the default values specified in the **Default Options** table above.
150+
151+
```bash
152+
# Run the generator using all default options
153+
cookiecutter https://github.com/microsoft/botbuilder-python/releases/download/Templates/echo.zip --no-input
154+
```
155+
156+
This example shows how to run the generator in --no-input mode, with unit tests.
157+
158+
```bash
159+
# PENDING: Run the generator using all default options
160+
```
161+
162+
## Running Your Bot
163+
164+
### Running Your Bot Locally
165+
166+
To run your bot locally, type the following in your console:
167+
168+
```bash
169+
# install dependencies
170+
pip install -r requirements.txt
171+
```
172+
173+
```bash
174+
# run the bot
175+
python app.py
176+
```
177+
178+
Alternatively to the last command, you can set the file in an environment variable with `set FLASK_APP=app.py` in windows (`export FLASK_APP=app.py` in mac/linux) and then run `flask run --host=127.0.0.1 --port=3978`
179+
180+
### Interacting With Your Bot Using the Emulator
181+
182+
- Launch Bot Framework Emulator
183+
- File -> Open Bot
184+
- Enter a Bot URL of `http://localhost:3978/api/messages`
185+
186+
Once the Emulator is connected, you can interact with and receive messages from your bot.
187+
188+
#### Lint Compliant Code
189+
190+
The code generated by the botbuilder generator is pylint compliant to our ruleset. To use pylint as your develop your bot:
191+
192+
```bash
193+
# Assuming you created a project with the bot_name value 'my_chat_bot'
194+
pylint --rcfile=my_chat_bot/.pylintrc my_chat_bot
195+
```
196+
197+
#### Testing Core Bots with Tests (Pending)
198+
199+
Core Bot templates generated with unit tests can be tested using the following:
200+
201+
```bash
202+
# launch pytest
203+
pytest
204+
```
205+
206+
## Deploy Your Bot to Azure (PENDING)
207+
208+
After creating the bot and testing it locally, you can deploy it to Azure to make it accessible from anywhere.
209+
To learn how, see [Deploy your bot to Azure](https://aka.ms/azuredeployment) for a complete set of deployment instructions.
210+
211+
If you are new to Microsoft Azure, please refer to [Getting started with Azure](https://azure.microsoft.com/get-started/) for guidance on how to get started on Azure.
212+
213+
## Logging Issues and Providing Feedback
214+
215+
Issues and feedback about the botbuilder generator can be submitted through the project's [GitHub Issues](https://github.com/Microsoft/botbuilder-samples/issues) page.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"project_name": "echo-bot",
3-
"bot_name": "Echo Bot",
4-
"bot_description": "This project shows a simple echo bot and demonstrates basic Bot Framework functionality."
2+
"bot_name": "my_chat_bot",
3+
"bot_description": "Demonstrate the core capabilities of the Microsoft Bot Framework"
54
}

0 commit comments

Comments
 (0)
0