Skip to content

Commit 950a745

Browse files
authored
0.1.0 (#22)
* Create Readme.md file Help document update * Header issue has fixed Number with Type header issue has fixed * Created CODEOWNERS file @arafattehsin I put you in as the default code owner of the repo since you've been gatekeeping some of the dotnet and python stuff. I'm fluent in Python code so I can do some reviews, but I don't have the bandwidth to work on this repo like I have been on the NodeJS one. * NumberWithTypePrompt doc has updated * Added phone_number prompt Phone prompt & unit test script has added * Added email prompt Added email prompt , test_email_prompt & Init.py * Added internet _protocol_prompt Added internet protocol prompt has added * Guid Prompt has added Guid Prompt has added in the Prompt group * Added new Dialog Prompts types Phone Number, Email Address, Internet Protocols , GUID dialogs has added * New Prompt type has added * Dialog-Prompts section added in README.md file. Dialog-Prompts section added * Set up CI with Azure Pipelines [skip ci] * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Pipeline updates (#20) * Updates for CI / pipelines * Update pipelines yml * More updates for pipelines * Updated dependencies * Update yml * Update coveralls settings and CI triggers * Remove black dependency and check * Added coveralls and pipelines badges to readme * Update azure-pipelines.yml for Azure Pipelines * Update README.md * Nudging build
1 parent e703bb1 commit 950a745

18 files changed

+807
-12
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[run]
2+
source = ./libraries/
3+
omit =
4+
*/tests/*

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
.vscode/

CODEOWNERS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# People marked here will be automatically requested for a review
2+
# when the code that they own is touched.
3+
# https://help.github.com/articles/about-codeowners/
4+
5+
# These owners will be the default owners for everything in
6+
# the repo. Unless a later match takes precedence,
7+
* @arafattehsin
8+
9+
# Library Owners
10+
libraries/botbuilder-community-dialogs-prompts/ @rvinothrajendran

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Bot Builder Community - Python Extensions
22

3+
[![Build Status](https://dev.azure.com/BotBuilder-Community/python/_apis/build/status/BotBuilderCommunity.botbuilder-community-python?branchName=develop)](https://dev.azure.com/BotBuilder-Community/python/_build/latest?definitionId=4&branchName=develop) [![Coverage Status](https://coveralls.io/repos/github/BotBuilderCommunity/botbuilder-community-python/badge.svg?branch=HEAD)](https://coveralls.io/github/BotBuilderCommunity/botbuilder-community-python?branch=HEAD)
4+
35
This repository is part of the Bot Builder Community Project and contains Bot Builder Extensions for the Python SDK, including middleware, dialogs, helpers and more. Other repos within the Bot Builder Community Project exist for extensions for [JavaScript](https://github.com/BotBuilderCommunity/botbuilder-community-js), [.NET](https://github.com/BotBuilderCommunity/botbuilder-community-dotnet), [Java](https://github.com/BotBuilderCommunity/botbuilder-community-java) and [tools](https://github.com/BotBuilderCommunity/botbuilder-community-tools) - you can find our other repos under [our GitHub organisation for the project](https://github.com/BotBuilderCommunity/).
46

5-
This repo will be updated shortly to add the first extensions - please contribute you own too!
7+
To see a list of current extensions available for the Bot Builder Python SDK, use the links below to jump to a section
8+
* [Dialogs & Prompts](#dialogs-and-prompts)
9+
10+
11+
## Dialogs and Prompts
12+
The following dialogs are currently available;
13+
14+
| Name | Description | Sample | PIP |
15+
| ---- | ----------- | ------- | --- |
16+
| [@botbuildercommunity/dialog-prompts](libraries/botbuilder-community-dialogs-prompts/README.md) | A variety of prompts using the [Microsoft Recognizers Text](https://github.com/microsoft/Recognizers-Text) suite, such as currency, temperature, age and dimension. | coming soon | coming soon |

azure-pipelines.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Python package
2+
# Create and test a Python package on multiple Python versions.
3+
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
4+
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
5+
6+
trigger:
7+
- master
8+
- develop
9+
- release/*
10+
- feature/*
11+
12+
pool:
13+
vmImage: 'ubuntu-latest'
14+
15+
steps:
16+
- task: UsePythonVersion@0
17+
inputs:
18+
versionSpec: '$(python.version)'
19+
displayName: 'Use Python $(python.version)'
20+
21+
- script: |
22+
python -m pip install --upgrade pip
23+
pip install -e ./libraries/botbuilder-community-dialogs-prompts
24+
pip install pytest pytest-azurepipelines
25+
pip install coveralls
26+
pip install pylint
27+
pip install pytest
28+
pip install pytest-cov
29+
displayName: 'Install dependencies'
30+
31+
- script: |
32+
pytest --junitxml=junit/test-results.xml --cov-config=.coveragerc --cov --cov-report=xml --cov-report=html
33+
displayName: Pytest
34+
35+
- task: PublishTestResults@2
36+
displayName: 'Publish Test Results **/test-results.xml'
37+
inputs:
38+
testResultsFiles: '**/test-results.xml'
39+
testRunTitle: 'Python $(python.version)'
40+
41+
- script: 'COVERALLS_REPO_TOKEN=sB4xSe7ZSZE3VgaoGvi7MVApbZD2x0n2T coveralls'
42+
displayName: 'Push test results to coveralls https://coveralls.io/github/BotBuilderCommunity/botbuilder-community-python'
43+
continueOnError: true
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Dialog Prompts
2+
3+
This is a (currently experimental) suite of dialog prompts that uses Microsoft's recognizer text suite to recognize certain types of input during a dialog prompt. Microsoft's Bot Framework team has implemented a handful of prompts using recognizers from the recognizer text suite. This library is meant to fill the gaps.
4+
5+
> Currently, this library and subsequent PIP are experimental. Please use at your own risk. Feel free to test, debug, and submit pull requests if you come across any issues.
6+
7+
## Installation
8+
9+
You can install this library via PIP:
10+
11+
## Coming soon
12+
13+
## Number with Unit
14+
15+
The number with unit prompt allows you to prompt for four different unit types:
16+
17+
* Currency
18+
* Temperature
19+
* Age
20+
* Dimension (eg. miles / meters)
21+
22+
```python
23+
dialogs.add(new NumberWithUnitPrompt('numberPrompt', NumberWithUnitPromptType.Currency);
24+
```
25+
26+
Then, you can call the bot by specifying your PromptOptions and calling PromptAsync.
27+
28+
```python
29+
options = PromptOptions(
30+
prompt = Activity(
31+
type = ActivityTypes.message,
32+
text = "Enter the curreny info"
33+
)
34+
)
35+
await step_context.prompt("numberprompt",options)
36+
37+
```
38+
39+
The prompt will return a NumberWithUnitResult.The object contains a value and unit type.
40+
For example, if a user enters "twenty three dollars" when you are using the Currency prompt type, the resulting NumberWithUnitResult object will have Unit: "Dollar", Value: "23". Below is an example of how you might use this result.
41+
42+
```python
43+
result = f"currency : {turn_context.result.value} and unit : {turn_context.result.unit}"
44+
await turn_context.send_activity(result)
45+
```
46+
47+
## Number with Type
48+
49+
Number with type allows you to accept numbers from the follow type enum:
50+
51+
* Ordinal
52+
* Percentage
53+
54+
```python
55+
dialogs.add(new NumberWithTypePrompt('numberPrompt', NumberWithTypePromptType.Ordinal);
56+
```
57+
The prompt will a return a result based on the NumberWithTypePromptType type.
58+
For example , If user enters “eleventh” Ordinal type return the result as 11.
59+
Below is an example of how you might use this result.
60+
61+
```python
62+
result = step_context.result
63+
await turn_context.send_activity(result)
64+
```
65+
66+
## Phone Number
67+
68+
The `PhoneNumberPrompt` will extract a phone number from a message from the user.
69+
70+
```python
71+
dialogs.add(new PhoneNumberPrompt('phprompt');
72+
```
73+
74+
Example
75+
76+
```python
77+
User : My phone number is 1 (877) 609-2233
78+
PhoneNumberPrompt return as 1 (877) 609-2233
79+
```
80+
81+
## Email Address
82+
83+
The `EmailPrompt` will extract an email address from a message from the user.
84+
85+
```python
86+
dialogs.add(new EmailPrompt('eprompt');
87+
```
88+
89+
Example
90+
91+
```python
92+
User : My email id is r.vinoth@live.com
93+
EmailPrompt return as r.vinoth@live.com
94+
```
95+
96+
## Internet Protocols
97+
98+
The `InternetProtocolPrompt` will extract one of the following types based on which InternetProtocolPromptType enum value is passed in:
99+
100+
* IPAddress
101+
* URL
102+
103+
```python
104+
dialogs.add(InternetProtocolPrompt("urlprompt",InternetProtocolPromptType.URL))
105+
```
106+
Example
107+
108+
```python
109+
User : My favorite web site is http://rvinothrajendran.github.io/
110+
InternetProtocolPrompt return as http://rvinothrajendran.github.io/
111+
```
112+
113+
## GUID
114+
115+
The `GUIDPrompt` will extract a GUID from a message from the user.
116+
117+
```python
118+
dialogs.add(new GuidPrompt('gprompt');
119+
```
120+
121+
Example
122+
123+
```python
124+
User : my azure id is "7d7b0205-9411-4a29-89ac-b9cd905886fa"
125+
GUIDPrompt return as "7d7b0205-9411-4a29-89ac-b9cd905886fa"
126+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
aiounittest>=1.3.0
2+
botbuilder-core>=4.5.0b5
3+
botbuilder-schema>=4.5.0b5
4+
botbuilder-dialogs>=4.5.0b5
5+
recognizers_text_suite>=1.0.2a2
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
from setuptools import setup
3+
4+
REQUIRES = [
5+
"botbuilder-core>=4.5.0b5",
6+
"botbuilder-schema>=4.5.0b5",
7+
"botbuilder-dialogs>=4.5.0b5",
8+
"recognizers_text_suite>=1.0.2a2",
9+
"aiounittest>=1.3.0"
10+
]
11+
12+
TESTS_REQUIRES = ["aiounittest>=1.3.0"]
13+
14+
root = os.path.abspath(os.path.dirname(__file__))
15+
16+
with open(os.path.join(root, "source", "about.py")) as f:
17+
package_info = {}
18+
info = f.read()
19+
exec(info, package_info)
20+
21+
with open(os.path.join(root, "README.md"), encoding="utf-8") as f:
22+
long_description = f.read()
23+
24+
setup(
25+
name=package_info["__title__"],
26+
version=package_info["__version__"],
27+
url=package_info["__uri__"],
28+
author=package_info["__author__"],
29+
description=package_info["__description__"],
30+
keywords="botbuilder bots ai botframework dialogs prompts",
31+
long_description=long_description,
32+
long_description_content_type="text/markdown",
33+
license=package_info["__license__"],
34+
packages=[
35+
"source",
36+
],
37+
install_requires=REQUIRES + TESTS_REQUIRES,
38+
tests_require=TESTS_REQUIRES,
39+
include_package_data=True,
40+
classifiers=[
41+
"Programming Language :: Python :: 3.7",
42+
"Intended Audience :: Developers",
43+
"License :: OSI Approved :: MIT License",
44+
"Operating System :: OS Independent",
45+
"Development Status :: 3 - Alpha",
46+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
47+
],
48+
)
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
from numberwithunit_prompt import (
2-
NumberWithUnitPrompt,
3-
NumberWithUnitPromptType,
4-
NumberWithUnitResult,
5-
NumberWithTypePromptType,
6-
NumberWithTypePrompt)
7-
1+
from .about import __version__
2+
from number_with_type_prompt import NumberWithTypePrompt, NumberWithTypePromptType
3+
from number_with_unit_prompt import NumberWithUnitPrompt, NumberWithUnitPromptType,NumberWithUnitResult
4+
from phone_prompt import PhoneNumberPrompt
5+
from email_prompt import EmailPrompt
6+
from internet_protocol_prompt import InternetProtocolPrompt,InternetProtocolPromptType
7+
from guid_prompt import GuidPrompt
8+
89
__all__ = [
910
"NumberWithUnitPrompt",
10-
"NumberWithUnitPromptType",
11-
"NumberWithUnitResult",
11+
"NumberWithUnitPromptType",
12+
"NumberWithUnitResult",
1213
"NumberWithTypePromptType",
13-
"NumberWithTypePrompt"
14-
]
14+
"NumberWithTypePrompt",
15+
"PhoneNumberPrompt",
16+
"EmailPrompt",
17+
"InternetProtocolPrompt",
18+
"InternetProtocolPromptType",
19+
"GuidPrompt",
20+
"__version__"
21+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
3+
__title__ = "botbuilder-community-dialogs-prompts"
4+
__version__ = (
5+
os.environ["packageVersion"] if "packageVersion" in os.environ else "0.1.0"
6+
)
7+
__uri__ = "https://www.github.com/Microsoft/botbuilder-python"
8+
__author__ = "Bot Builder Community"
9+
__description__ = "Microsoft Bot Builder Community Dialogs Prompts"
10+
__summary__ = "Dialogs Prompts from the Bot Builder Community for Microsoft Bot Builder SDK for Python"
11+
__license__ = "MIT"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from botbuilder.dialogs.prompts import Prompt, PromptOptions,PromptRecognizerResult
2+
from botbuilder.core.turn_context import TurnContext
3+
from botbuilder.schema import ActivityTypes
4+
from recognizers_text import Culture, ModelResult,StringUtility
5+
from recognizers_sequence import SequenceRecognizer
6+
7+
from typing import Callable, Dict
8+
import enum
9+
10+
class EmailPrompt (Prompt):
11+
def __init__(self,
12+
dialog_id,
13+
validator : object = None,
14+
defaultLocale = None):
15+
super().__init__(dialog_id, validator=validator)
16+
17+
if defaultLocale is None:
18+
defaultLocale = Culture.English
19+
20+
self._defaultLocale = defaultLocale
21+
22+
async def on_prompt(
23+
self,
24+
turn_context: TurnContext,
25+
state: Dict[str, object],
26+
options: PromptOptions,
27+
is_retry: bool,
28+
):
29+
if not turn_context:
30+
raise TypeError("turn_context Can’t be none")
31+
if not options:
32+
raise TypeError("options Can’t be none")
33+
34+
if is_retry and options.retry_prompt is not None:
35+
await turn_context.send_activity(options.retry_prompt)
36+
else:
37+
if options.prompt is not None:
38+
await turn_context.send_activity(options.prompt)
39+
40+
async def on_recognize(self,
41+
turn_context: TurnContext,
42+
state: Dict[str, object],
43+
options: PromptOptions,
44+
) -> PromptRecognizerResult:
45+
if not turn_context:
46+
raise TypeError("turn_context Can’t be none")
47+
48+
if turn_context.activity.type == ActivityTypes.message:
49+
utterance = turn_context.activity.text
50+
51+
turn_context.activity.locale = self._defaultLocale
52+
53+
recognizer_result = PromptRecognizerResult()
54+
55+
recognizer = SequenceRecognizer(turn_context.activity.locale)
56+
model = recognizer.get_email_model()
57+
58+
model_result = model.parse(utterance)
59+
60+
if len(model_result) > 0 and len(model_result[0].resolution) > 0:
61+
recognizer_result.succeeded = True
62+
recognizer_result.value = model_result[0].resolution["value"]
63+
64+
return recognizer_result

0 commit comments

Comments
 (0)