├── .coveragerc ├── .gitignore ├── CODEOWNERS ├── LICENSE ├── README.md ├── azure-pipelines.yml └── libraries ├── botbuilder-community-dialogs-prompts ├── README.md ├── botbuilder │ └── community │ │ └── dialogs │ │ └── prompts │ │ ├── __init__.py │ │ ├── about.py │ │ ├── email_prompt.py │ │ ├── guid_prompt.py │ │ ├── internet_protocol_prompt.py │ │ ├── number_with_type_prompt.py │ │ ├── number_with_unit_prompt.py │ │ └── phone_prompt.py ├── requirements.txt ├── setup.py └── test │ ├── test_email_prompt.py │ ├── test_guid_prompt.py │ ├── test_internet_protocol_prompt.py │ ├── test_number_with_type_prompt.py │ ├── test_number_with_unit_prompt.py │ └── test_phone_prompt.py ├── botbuilder-community-middleware-activity-type ├── README.md ├── botbuilder │ └── community │ │ └── middleware │ │ └── activity │ │ └── type │ │ ├── __init__.py │ │ ├── about.py │ │ └── activity_type_middleware.py ├── requirements.txt ├── setup.py └── test │ └── test_activity_type_middleware.py └── botbuilder-community-middleware-text-recognizer ├── README.md ├── botbuilder └── community │ └── middleware │ └── text │ └── recognizer │ ├── __init__.py │ ├── about.py │ ├── email_middleware.py │ ├── phone_middleware.py │ ├── social_media_middleware.py │ └── url_middleware.py ├── requirements.txt ├── setup.py └── test ├── test_email_middleware.py ├── test_phone_middleware.py ├── test_social_middleware.py └── test_url_middleware.py /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = ./libraries/ 3 | omit = 4 | */tests/* -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | .vscode/ 107 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Bot Builder Community 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bot Builder Community - Python Extensions 2 | 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 | 5 | 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/). 6 | 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 | [botbuilder-community-dialogs-prompts](https://pypi.org/project/botbuilder-community-dialogs-prompts/) | 17 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 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 -e ./libraries/botbuilder-community-middleware-activity-type 25 | pip install -e ./libraries/botbuilder-community-middleware-text-recognizer 26 | pip install pytest pytest-azurepipelines 27 | pip install coveralls 28 | pip install pylint 29 | pip install pytest 30 | pip install pytest-cov 31 | displayName: 'Install dependencies' 32 | 33 | - script: | 34 | python -m pytest --junitxml=junit/test-results.xml --cov-config=.coveragerc --cov --cov-report=xml --cov-report=html 35 | displayName: Pytest 36 | 37 | - task: PublishTestResults@2 38 | displayName: 'Publish Test Results **/test-results.xml' 39 | inputs: 40 | testResultsFiles: '**/test-results.xml' 41 | testRunTitle: 'Python $(python.version)' 42 | 43 | - script: 'COVERALLS_REPO_TOKEN=sB4xSe7ZSZE3VgaoGvi7MVApbZD2x0n2T coveralls' 44 | displayName: 'Push test results to coveralls https://coveralls.io/github/BotBuilderCommunity/botbuilder-community-python' 45 | continueOnError: true -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/README.md: -------------------------------------------------------------------------------- 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 | ## Installation 6 | 7 | You can install this library via PIP: 8 | 9 | pip install botbuilder-community-dialogs-prompts 10 | 11 | You can then import required types, for example: 12 | 13 | ```python 14 | from botbuilder.community.dialogs.prompts import NumberWithUnitPrompt, NumberWithUnitPromptType 15 | ``` 16 | 17 | ## Number with Unit 18 | 19 | The number with unit prompt allows you to prompt for four different unit types: 20 | 21 | * Currency 22 | * Temperature 23 | * Age 24 | * Dimension (eg. miles / meters) 25 | 26 | ```python 27 | self._dialogs.add(NumberWithUnitPrompt('numberPrompt',NumberWithUnitPromptType.Currency)) 28 | ``` 29 | 30 | Then, you can call the bot by specifying your PromptOptions and calling PromptAsync. 31 | 32 | ```python 33 | options = PromptOptions( 34 | prompt = Activity( 35 | type = ActivityTypes.message, 36 | text = "Enter the curreny info" 37 | ) 38 | ) 39 | await step_context.prompt("numberprompt",options) 40 | 41 | ``` 42 | 43 | The prompt will return a NumberWithUnitResult.The object contains a value and unit type. 44 | 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. 45 | 46 | ```python 47 | result = f"currency : {turn_context.result.value} and unit : {turn_context.result.unit}" 48 | await turn_context.send_activity(result) 49 | ``` 50 | 51 | ## Number with Type 52 | 53 | Number with type allows you to accept numbers from the follow type enum: 54 | 55 | * Ordinal 56 | * Percentage 57 | 58 | ```python 59 | self._dialogs.add(NumberWithTypePrompt(numberunit,NumberWithTypePromptType.Ordinal)) 60 | ``` 61 | The prompt will a return a result based on the NumberWithTypePromptType type. 62 | For example , If user enters “eleventh” Ordinal type return the result as 11. 63 | Below is an example of how you might use this result. 64 | 65 | ```python 66 | result = step_context.result 67 | await turn_context.send_activity(result) 68 | ``` 69 | 70 | ## Phone Number 71 | 72 | The `PhoneNumberPrompt` will extract a phone number from a message from the user. 73 | 74 | ```python 75 | self._dialogs.add(PhoneNumberPrompt('phprompt')) 76 | ``` 77 | 78 | Example 79 | 80 | ```python 81 | User : My phone number is 1 (877) 609-2233 82 | PhoneNumberPrompt return as 1 (877) 609-2233 83 | ``` 84 | 85 | ## Email Address 86 | 87 | The `EmailPrompt` will extract an email address from a message from the user. 88 | 89 | ```python 90 | self._dialogs.add(EmailPrompt('eprompt')) 91 | ``` 92 | 93 | Example 94 | 95 | ```python 96 | User : My email id is r.vinoth@live.com 97 | EmailPrompt return as r.vinoth@live.com 98 | ``` 99 | 100 | ## Internet Protocols 101 | 102 | The `InternetProtocolPrompt` will extract one of the following types based on which InternetProtocolPromptType enum value is passed in: 103 | 104 | * IPAddress 105 | * URL 106 | 107 | ```python 108 | self._dialogs.add(InternetProtocolPrompt('urlprompt',InternetProtocolPromptType.URL)) 109 | ``` 110 | Example 111 | 112 | ```python 113 | User : My favorite web site is http://rvinothrajendran.github.io/ 114 | InternetProtocolPrompt return as http://rvinothrajendran.github.io/ 115 | ``` 116 | 117 | ## GUID 118 | 119 | The `GUIDPrompt` will extract a GUID from a message from the user. 120 | 121 | ```python 122 | self._dialogs.add(GuidPrompt('gprompt')) 123 | ``` 124 | 125 | Example 126 | 127 | ```python 128 | User : my azure id is "7d7b0205-9411-4a29-89ac-b9cd905886fa" 129 | GUIDPrompt return as "7d7b0205-9411-4a29-89ac-b9cd905886fa" 130 | ``` 131 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/__init__.py: -------------------------------------------------------------------------------- 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 | 9 | __all__ = [ 10 | "NumberWithUnitPrompt", 11 | "NumberWithUnitPromptType", 12 | "NumberWithUnitResult", 13 | "NumberWithTypePromptType", 14 | "NumberWithTypePrompt", 15 | "PhoneNumberPrompt", 16 | "EmailPrompt", 17 | "InternetProtocolPrompt", 18 | "InternetProtocolPromptType", 19 | "GuidPrompt", 20 | "__version__" 21 | ] -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/about.py: -------------------------------------------------------------------------------- 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://github.com/BotBuilderCommunity/botbuilder-community-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" -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/email_prompt.py: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/guid_prompt.py: -------------------------------------------------------------------------------- 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 | from typing import Callable, Dict 7 | 8 | 9 | class GuidPrompt (Prompt): 10 | def __init__(self, 11 | dialog_id, 12 | validator : object = None, 13 | defaultLocale = None): 14 | super().__init__(dialog_id, validator=validator) 15 | if defaultLocale is None: 16 | defaultLocale = Culture.English 17 | 18 | self._defaultLocale = defaultLocale 19 | 20 | 21 | async def on_prompt(self, turn_context, state, options, is_retry): 22 | if not turn_context: 23 | raise TypeError("turn_context Can’t be none") 24 | if not options: 25 | raise TypeError("options Can’t be none") 26 | 27 | if is_retry and options.retry_prompt is not None: 28 | await turn_context.send_activity(options.retry_prompt) 29 | else: 30 | if options.prompt is not None: 31 | await turn_context.send_activity(options.prompt) 32 | 33 | async def on_recognize( self, 34 | turn_context: TurnContext, 35 | state: Dict[str, object], 36 | options: PromptOptions) -> PromptRecognizerResult(): 37 | if not turn_context: 38 | raise TypeError("turn_context Can’t be none") 39 | 40 | if turn_context.activity.type == ActivityTypes.message: 41 | utterance = turn_context.activity.text 42 | 43 | turn_context.activity.locale = self._defaultLocale 44 | 45 | recognizer_result = PromptRecognizerResult() 46 | 47 | mode = SequenceRecognizer(turn_context.activity.locale) 48 | model = mode.get_guid_model() 49 | 50 | model_result = model.parse(utterance) 51 | 52 | if len(model_result) > 0 and len(model_result[0].resolution) > 0: 53 | recognizer_result.succeeded = True 54 | recognizer_result.value = model_result[0].resolution["value"] 55 | 56 | return recognizer_result -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/internet_protocol_prompt.py: -------------------------------------------------------------------------------- 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_sequence import SequenceRecognizer 5 | from recognizers_text import Culture, ModelResult 6 | from typing import Callable, Dict 7 | import enum 8 | 9 | class InternetProtocolPromptType(enum.Enum): 10 | IPAddress = 0, 11 | URL = 1, 12 | 13 | class InternetProtocolPrompt(Prompt): 14 | def __init__(self, 15 | dialog_id, 16 | promptType:InternetProtocolPromptType, 17 | validator : object = None, 18 | defaultLocale = None): 19 | super().__init__(dialog_id,validator) 20 | 21 | if defaultLocale is None: 22 | defaultLocale = Culture.English 23 | 24 | self._defaultLocale = defaultLocale 25 | self._promptType = promptType 26 | 27 | async def on_prompt( 28 | self, 29 | turn_context: TurnContext, 30 | state: Dict[str, object], 31 | options: PromptOptions, 32 | is_retry: bool): 33 | if not turn_context: 34 | raise TypeError("turn_context Can’t be none") 35 | if not options: 36 | raise TypeError("options Can’t be none") 37 | 38 | if is_retry and options.retry_prompt is not None: 39 | await turn_context.send_activity(options.retry_prompt) 40 | else: 41 | if options.prompt is not None: 42 | await turn_context.send_activity(options.prompt) 43 | 44 | async def on_recognize(self, 45 | turn_context: TurnContext, 46 | state: Dict[str, object], 47 | options: PromptOptions, 48 | ) -> PromptRecognizerResult: 49 | if not turn_context: 50 | raise TypeError("turn_context Can’t be none") 51 | 52 | if turn_context.activity.type == ActivityTypes.message: 53 | utterance = turn_context.activity.text 54 | 55 | turn_context.activity.locale = self._defaultLocale 56 | 57 | recognizer_result = PromptRecognizerResult() 58 | mode = SequenceRecognizer(turn_context.activity.locale) 59 | 60 | if (self._promptType == InternetProtocolPromptType.IPAddress): 61 | model = mode.get_ip_address_model() 62 | elif (self._promptType == InternetProtocolPromptType.URL): 63 | model = mode.get_url_model() 64 | 65 | model_result = model.parse(utterance) 66 | if len(model_result) > 0 and len(model_result[0].resolution) > 0: 67 | recognizer_result.succeeded = True 68 | recognizer_result.value = model_result[0].resolution["value"] 69 | 70 | return recognizer_result -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/number_with_type_prompt.py: -------------------------------------------------------------------------------- 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_number import NumberRecognizer 5 | from recognizers_text import Culture, ModelResult 6 | from typing import Callable, Dict 7 | import enum 8 | 9 | class NumberWithTypePromptType(enum.Enum): 10 | Ordinal = 0, 11 | Percentage = 1 12 | 13 | 14 | class NumberWithTypePrompt(Prompt): 15 | def __init__( 16 | self, 17 | dialog_id, 18 | prompt_type : NumberWithTypePromptType, 19 | validator: object = None, 20 | default_locale = None 21 | ): 22 | super().__init__(dialog_id, validator) 23 | 24 | if default_locale is None: 25 | default_locale = Culture.English 26 | 27 | self._default_locale = default_locale 28 | self._prompt_type = prompt_type 29 | 30 | async def on_prompt( 31 | self, 32 | turn_context: TurnContext, 33 | state: Dict[str, object], 34 | options: PromptOptions, 35 | is_retry: bool, 36 | ): 37 | if not turn_context: 38 | raise TypeError("turn_context can’t be none") 39 | if not options: 40 | raise TypeError("options can’t be none") 41 | 42 | if is_retry and options.retry_prompt is not None: 43 | await turn_context.send_activity(options.retry_prompt) 44 | else: 45 | if options.prompt is not None: 46 | await turn_context.send_activity(options.prompt) 47 | 48 | async def on_recognize( 49 | self, 50 | turn_context: TurnContext, 51 | state: Dict[str, object], 52 | options: PromptOptions, 53 | ) -> PromptRecognizerResult: 54 | if not turn_context: 55 | raise TypeError("turn_context can’t be none") 56 | 57 | if turn_context.activity.type == ActivityTypes.message: 58 | utterance = turn_context.activity.text 59 | 60 | turn_context.activity.locale = self._default_locale 61 | 62 | recognizer_result = PromptRecognizerResult() 63 | 64 | recognizer = NumberRecognizer(turn_context.activity.locale) 65 | 66 | if (self._prompt_type == NumberWithTypePromptType.Ordinal): 67 | model = recognizer.get_ordinal_model() 68 | elif (self._prompt_type == NumberWithTypePromptType.Percentage): 69 | model = recognizer.get_percentage_model() 70 | 71 | model_result = model.parse(utterance) 72 | if len(model_result) > 0 and len(model_result[0].resolution) > 0: 73 | recognizer_result.succeeded = True 74 | recognizer_result.value = model_result[0].resolution["value"] 75 | 76 | return recognizer_result -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/number_with_unit_prompt.py: -------------------------------------------------------------------------------- 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_number_with_unit import NumberWithUnitRecognizer 5 | from recognizers_text import Culture, ModelResult 6 | from typing import Callable, Dict 7 | import enum 8 | 9 | class NumberWithUnitPromptType(enum.Enum): 10 | Currency = 0 11 | Temperature = 1 12 | Age = 2 13 | Dimension = 3 14 | 15 | class NumberWithUnitResult: 16 | def __init__(self, unit , value ): 17 | self._unit = unit 18 | self._value = value 19 | 20 | @property 21 | def unit(self): 22 | return self._unit 23 | @property 24 | def value(self): 25 | return self._value 26 | 27 | 28 | class NumberWithUnitPrompt(Prompt): 29 | def __init__( 30 | self, 31 | dialog_id, 32 | prompt_type: NumberWithUnitPromptType, 33 | validator: object = None, 34 | default_locale = None 35 | ): 36 | super().__init__(dialog_id, validator) 37 | 38 | if default_locale is None: 39 | default_locale = Culture.English 40 | 41 | self._default_locale = default_locale 42 | self._prompt_type = prompt_type 43 | 44 | async def on_prompt( 45 | self, 46 | turn_context: TurnContext, 47 | state: Dict[str, object], 48 | options: PromptOptions, 49 | is_retry: bool, 50 | ): 51 | if not turn_context: 52 | raise TypeError("turn_context can’t be none") 53 | if not options: 54 | raise TypeError("options can’t be none") 55 | 56 | if is_retry and options.retry_prompt is not None: 57 | await turn_context.send_activity(options.retry_prompt) 58 | else: 59 | if options.prompt is not None: 60 | await turn_context.send_activity(options.prompt) 61 | 62 | async def on_recognize( 63 | self, 64 | turn_context: TurnContext, 65 | state: Dict[str, object], 66 | options: PromptOptions, 67 | ) -> PromptRecognizerResult: 68 | if not turn_context: 69 | raise TypeError("turn_context can’t be none") 70 | 71 | if turn_context.activity.type == ActivityTypes.message: 72 | utterance = turn_context.activity.text 73 | 74 | turn_context.activity.locale = self._default_locale 75 | 76 | recognizer_result = PromptRecognizerResult() 77 | 78 | recognizer = NumberWithUnitRecognizer(turn_context.activity.locale) 79 | 80 | if self._prompt_type == NumberWithUnitPromptType.Age: 81 | model = recognizer.get_age_model() 82 | elif self._prompt_type == NumberWithUnitPromptType.Currency: 83 | model = recognizer.get_currency_model() 84 | elif self._prompt_type == NumberWithUnitPromptType.Dimension: 85 | model = recognizer.get_dimension_model() 86 | elif self._prompt_type == NumberWithUnitPromptType.Temperature: 87 | model = recognizer.get_temperature_model() 88 | 89 | model_result = model.parse(utterance) 90 | 91 | if len(model_result) > 0 and len(model_result[0].resolution) > 1: 92 | recognizer_result.succeeded = True 93 | recognizer_result.value = NumberWithUnitResult( 94 | model_result[0].resolution["unit"], 95 | model_result[0].resolution["value"] 96 | ) 97 | 98 | return recognizer_result -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/botbuilder/community/dialogs/prompts/phone_prompt.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | from botbuilder.dialogs.prompts import ( 3 | Prompt, 4 | PromptOptions, 5 | PromptRecognizerResult 6 | ) 7 | from botbuilder.core.turn_context import TurnContext 8 | from botbuilder.schema import ActivityTypes 9 | from recognizers_text import Culture, ModelResult 10 | from recognizers_sequence import SequenceRecognizer 11 | from typing import Callable, Dict 12 | 13 | class PhoneNumberPrompt (Prompt): 14 | def __init__( 15 | self, 16 | dialog_id, 17 | validator : object = None, 18 | default_locale = None): 19 | super().__init__(dialog_id, validator = validator) 20 | 21 | if default_locale is None: 22 | default_locale = Culture.English 23 | 24 | self._default_locale = default_locale 25 | 26 | async def on_prompt( 27 | self, 28 | turn_context: TurnContext, 29 | state: Dict[str, object], 30 | options: PromptOptions, 31 | is_retry: bool, 32 | ): 33 | if not turn_context: 34 | raise TypeError("turn_context Can’t be none") 35 | if not options: 36 | raise TypeError("options Can’t be none") 37 | 38 | if is_retry and options.retry_prompt is not None: 39 | await turn_context.send_activity(options.retry_prompt) 40 | else: 41 | if options.prompt is not None: 42 | await turn_context.send_activity(options.prompt) 43 | 44 | async def on_recognize( 45 | self, 46 | turn_context: TurnContext, 47 | state: Dict[str, object], 48 | options: PromptOptions, 49 | ) -> PromptRecognizerResult: 50 | 51 | if not turn_context: 52 | raise TypeError("turn_context Can’t be none") 53 | 54 | if turn_context.activity.type == ActivityTypes.message: 55 | utterance = turn_context.activity.text 56 | 57 | turn_context.activity.locale = self._default_locale 58 | 59 | result = PromptRecognizerResult() 60 | 61 | sequence_recongnizer = SequenceRecognizer(turn_context.activity.locale) 62 | phone_model = sequence_recongnizer.get_phone_number_model() 63 | phone_parse = phone_model.parse(utterance) 64 | 65 | if len(phone_parse) > 0 and len(phone_parse[0].resolution) > 0: 66 | result.succeeded = True 67 | result.value = phone_parse[0].resolution["value"] 68 | 69 | return result -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/requirements.txt: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/setup.py: -------------------------------------------------------------------------------- 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, "botbuilder", "community", "dialogs", "prompts", "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 | "botbuilder.community.dialogs.prompts", 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 | ) -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_email_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | from botbuilder.schema import Activity, ActivityTypes, Attachment 24 | from botbuilder.core.adapters import TestAdapter 25 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 26 | from email_prompt import EmailPrompt 27 | 28 | class EmailPromptTest(aiounittest.AsyncTestCase): 29 | async def test_email_prompt(self): 30 | async def exec_test(turn_context:TurnContext): 31 | dialog_context = await dialogs.create_context(turn_context) 32 | 33 | results = await dialog_context.continue_dialog() 34 | if (results.status == DialogTurnStatus.Empty): 35 | options = PromptOptions( 36 | prompt = Activity( 37 | type = ActivityTypes.message, 38 | text = "What is your email address?" 39 | ) 40 | ) 41 | await dialog_context.prompt("emailprompt", options) 42 | 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | await turn_context.send_activity(reply) 46 | 47 | await conv_state.save_changes(turn_context) 48 | 49 | adapter = TestAdapter(exec_test) 50 | 51 | conv_state = ConversationState(MemoryStorage()) 52 | 53 | dialog_state = conv_state.create_property("dialog-state") 54 | dialogs = DialogSet(dialog_state) 55 | dialogs.add(EmailPrompt("emailprompt")) 56 | 57 | step1 = await adapter.test('Hello', 'What is your email address?') 58 | step2 = await step1.send('My email id is r.vinoth@live.com') 59 | await step2.assert_reply("r.vinoth@live.com") -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_guid_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | from botbuilder.schema import Activity, ActivityTypes, Attachment 24 | from botbuilder.core.adapters import TestAdapter 25 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 26 | from guid_prompt import GuidPrompt 27 | 28 | class GuidPromptTest(aiounittest.AsyncTestCase): 29 | async def test_guid_phone_prompt(self): 30 | async def exec_test(turn_context:TurnContext): 31 | dialog_context = await dialogs.create_context(turn_context) 32 | 33 | results = await dialog_context.continue_dialog() 34 | if (results.status == DialogTurnStatus.Empty): 35 | options = PromptOptions( 36 | prompt = Activity( 37 | type = ActivityTypes.message, 38 | text = "test the guid format" 39 | ) 40 | ) 41 | await dialog_context.prompt("guidprompt", options) 42 | 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | await turn_context.send_activity(reply) 46 | 47 | await conv_state.save_changes(turn_context) 48 | 49 | adapter = TestAdapter(exec_test) 50 | 51 | conv_state = ConversationState(MemoryStorage()) 52 | 53 | dialog_state = conv_state.create_property("dialog-state") 54 | dialogs = DialogSet(dialog_state) 55 | dialogs.add(GuidPrompt("guidprompt")) 56 | 57 | step1 = await adapter.test('Hello', 'test the guid format') 58 | step2 = await step1.send('my azure id is 7d7b0205-9411-4a29-89ac-b9cd905886fa') 59 | await step2.assert_reply("7d7b0205-9411-4a29-89ac-b9cd905886fa") -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_internet_protocol_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | from botbuilder.schema import Activity, ActivityTypes, Attachment 24 | from botbuilder.core.adapters import TestAdapter 25 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 26 | from internet_protocol_prompt import InternetProtocolPrompt,InternetProtocolPromptType 27 | 28 | class InternetProtocolPromptTest(aiounittest.AsyncTestCase): 29 | async def test_ip_address_prompt(self): 30 | async def exec_test(turn_context:TurnContext): 31 | dialog_context = await dialogs.create_context(turn_context) 32 | 33 | results = await dialog_context.continue_dialog() 34 | if (results.status == DialogTurnStatus.Empty): 35 | options = PromptOptions( 36 | prompt = Activity( 37 | type = ActivityTypes.message, 38 | text = "What is your DNS?" 39 | ) 40 | ) 41 | await dialog_context.prompt("ipaddressprompt", options) 42 | 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | await turn_context.send_activity(reply) 46 | 47 | await conv_state.save_changes(turn_context) 48 | 49 | adapter = TestAdapter(exec_test) 50 | 51 | conv_state = ConversationState(MemoryStorage()) 52 | 53 | dialog_state = conv_state.create_property("dialog-state") 54 | dialogs = DialogSet(dialog_state) 55 | dialogs.add(InternetProtocolPrompt("ipaddressprompt",InternetProtocolPromptType.IPAddress)) 56 | 57 | step1 = await adapter.test('Hello', 'What is your DNS?') 58 | step2 = await step1.send('am using microsoft DNS 127.0.0.1') 59 | await step2.assert_reply("127.0.0.1") 60 | 61 | 62 | async def test_ip_url_prompt(self): 63 | async def exec_test(turn_context:TurnContext): 64 | dialog_context = await dialogs.create_context(turn_context) 65 | 66 | results = await dialog_context.continue_dialog() 67 | if (results.status == DialogTurnStatus.Empty): 68 | options = PromptOptions( 69 | prompt = Activity( 70 | type = ActivityTypes.message, 71 | text = "What is your favorite web site?" 72 | ) 73 | ) 74 | await dialog_context.prompt("urlprompt", options) 75 | 76 | elif results.status == DialogTurnStatus.Complete: 77 | reply = results.result 78 | await turn_context.send_activity(reply) 79 | 80 | await conv_state.save_changes(turn_context) 81 | 82 | adapter = TestAdapter(exec_test) 83 | 84 | conv_state = ConversationState(MemoryStorage()) 85 | 86 | dialog_state = conv_state.create_property("dialog-state") 87 | dialogs = DialogSet(dialog_state) 88 | dialogs.add(InternetProtocolPrompt("urlprompt",InternetProtocolPromptType.URL)) 89 | 90 | step1 = await adapter.test('Hello', 'What is your favorite web site?') 91 | step2 = await step1.send('My favorite web site is http://rvinothrajendran.github.io/') 92 | await step2.assert_reply("http://rvinothrajendran.github.io/") -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_number_with_type_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | 24 | from botbuilder.schema import Activity, ActivityTypes, Attachment 25 | from botbuilder.core.adapters import TestAdapter 26 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 27 | from number_with_type_prompt import NumberWithTypePrompt, NumberWithTypePromptType 28 | 29 | class NumberWithTypeOrdinalPromptTests(aiounittest.AsyncTestCase): 30 | async def test_ordinal_prompt(self): 31 | async def exec_test(turn_context:TurnContext): 32 | dialog_context = await dialogs.create_context(turn_context) 33 | 34 | results = await dialog_context.continue_dialog() 35 | if results.status == DialogTurnStatus.Empty: 36 | options = PromptOptions( 37 | prompt = Activity( 38 | type = ActivityTypes.message, 39 | text = "test the ordinalnumber type api" 40 | ) 41 | ) 42 | await dialog_context.prompt("ordinal_number_prompt", options) 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | await turn_context.send_activity(reply) 46 | 47 | await conv_state.save_changes(turn_context) 48 | 49 | adapter = TestAdapter(exec_test) 50 | 51 | conv_state = ConversationState(MemoryStorage()) 52 | 53 | dialog_state = conv_state.create_property("dialog-state") 54 | dialogs = DialogSet(dialog_state) 55 | dialogs.add(NumberWithTypePrompt("ordinal_number_prompt", NumberWithTypePromptType.Ordinal)) 56 | 57 | step1 = await adapter.test('Hello', 'test the ordinalnumber type api') 58 | step2 = await step1.send('tenth') 59 | await step2.assert_reply("10") 60 | 61 | 62 | class NumberWithPercentagePrompt(aiounittest.AsyncTestCase): 63 | async def test_percentage_prompt(self): 64 | async def exec_test(turn_context:TurnContext): 65 | dialog_context = await dialogs.create_context(turn_context) 66 | 67 | results = await dialog_context.continue_dialog() 68 | 69 | if results.status == DialogTurnStatus.Empty: 70 | options = PromptOptions( 71 | prompt = Activity( 72 | type = ActivityTypes.message, 73 | text = "test the percentage type api" 74 | ) 75 | ) 76 | await dialog_context.prompt("percentagePrompt", options) 77 | elif results.status == DialogTurnStatus.Complete: 78 | reply = results.result 79 | await turn_context.send_activity(reply) 80 | 81 | await conv_state.save_changes(turn_context) 82 | 83 | adapter = TestAdapter(exec_test) 84 | 85 | conv_state = ConversationState(MemoryStorage()) 86 | 87 | dialog_state = conv_state.create_property("dialog-state") 88 | dialogs = DialogSet(dialog_state) 89 | dialogs.add(NumberWithTypePrompt("percentagePrompt", NumberWithTypePromptType.Percentage)) 90 | 91 | step1 = await adapter.test('percentagePrompt', 'test the percentage type api') 92 | step2 = await step1.send('two hundred percents') 93 | await step2.assert_reply("200%") -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_number_with_unit_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | 24 | from botbuilder.schema import Activity, ActivityTypes, Attachment 25 | from botbuilder.core.adapters import TestAdapter 26 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 27 | from number_with_unit_prompt import NumberWithUnitPrompt, NumberWithUnitPromptType 28 | 29 | class NumberWithUnitAgePromptTests(aiounittest.AsyncTestCase): 30 | async def test_age_unit_prompt(self): 31 | async def exec_test(turn_context:TurnContext): 32 | dialog_context = await dialogs.create_context(turn_context) 33 | results = await dialog_context.continue_dialog() 34 | 35 | if results.status == DialogTurnStatus.Empty: 36 | options = PromptOptions( 37 | prompt = Activity( 38 | type = ActivityTypes.message, 39 | text = "test the age unit api" 40 | ) 41 | ) 42 | await dialog_context.prompt("AgePrompt", options) 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | result = f"Age : {reply.value} and unit : {reply.unit}" 46 | await turn_context.send_activity(result) 47 | 48 | await conv_state.save_changes(turn_context) 49 | 50 | adapter = TestAdapter(exec_test) 51 | 52 | conv_state = ConversationState(MemoryStorage()) 53 | 54 | dialog_state = conv_state.create_property("dialog-state") 55 | dialogs = DialogSet(dialog_state) 56 | dialogs.add(NumberWithUnitPrompt("AgePrompt", NumberWithUnitPromptType.Age)) 57 | 58 | step1 = await adapter.test('Hello', 'test the age unit api') 59 | step2 = await step1.send('am twenty seven years of age') 60 | await step2.assert_reply("Age : 27 and unit : Year") 61 | 62 | class NumberWithUnitCurrencyPromptTests(aiounittest.AsyncTestCase): 63 | async def test_currency_prompt(self): 64 | async def exec_test(turn_context:TurnContext): 65 | dialog_context = await dialogs.create_context(turn_context) 66 | results = await dialog_context.continue_dialog() 67 | 68 | if results.status == DialogTurnStatus.Empty: 69 | options = PromptOptions( 70 | prompt=Activity( 71 | type = ActivityTypes.message, 72 | text="test the currency unit api" 73 | ) 74 | ) 75 | await dialog_context.prompt("currencyprompt",options) 76 | elif results.status == DialogTurnStatus.Complete: 77 | reply = results.result 78 | result = f"currency : '{reply.value}' and unit : '{reply.unit}'" 79 | await turn_context.send_activity(result) 80 | 81 | await conv_state.save_changes(turn_context) 82 | 83 | adapter = TestAdapter(exec_test) 84 | 85 | conv_state = ConversationState(MemoryStorage()) 86 | 87 | dialog_state = conv_state.create_property("dialog-state") 88 | dialogs = DialogSet(dialog_state) 89 | dialogs.add(NumberWithUnitPrompt("currencyprompt",NumberWithUnitPromptType.Currency)) 90 | 91 | step1 = await adapter.test('Hello','test the currency unit api') 92 | step2 = await step1.send('Interest expense in the 2018 third quarter was $ 15.3 million') 93 | await step2.assert_reply("currency : '15300000' and unit : 'Dollar'") 94 | 95 | class NumberWithDimensionsPromptTests(aiounittest.AsyncTestCase): 96 | async def test_dimensions_prompt(self): 97 | async def exec_test(turn_context:TurnContext): 98 | dialog_context = await dialogs.create_context(turn_context) 99 | results = await dialog_context.continue_dialog() 100 | 101 | if results.status == DialogTurnStatus.Empty: 102 | options = PromptOptions( 103 | prompt = Activity( 104 | type = ActivityTypes.message, 105 | text = "test the Dimensions unit api" 106 | ) 107 | ) 108 | await dialog_context.prompt("Dimensionsprompt", options) 109 | elif results.status == DialogTurnStatus.Complete: 110 | reply = results.result 111 | result = f"Dimensions : '{reply.value}' and unit : '{reply.unit}'" 112 | await turn_context.send_activity(result) 113 | 114 | await conv_state.save_changes(turn_context) 115 | 116 | adapter = TestAdapter(exec_test) 117 | 118 | conv_state = ConversationState(MemoryStorage()) 119 | 120 | dialog_state = conv_state.create_property("dialog-state") 121 | dialogs = DialogSet(dialog_state) 122 | dialogs.add(NumberWithUnitPrompt("Dimensionsprompt", NumberWithUnitPromptType.Dimension)) 123 | 124 | step1 = await adapter.test('Hello', 'test the Dimensions unit api') 125 | step2 = await step1.send('The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours') 126 | await step2.assert_reply("Dimensions : '6' and unit : 'Mile'") 127 | 128 | class NumberWithTemperaturePromptTests(aiounittest.AsyncTestCase): 129 | async def test_temperature_prompt(self): 130 | async def exec_test(turn_context:TurnContext): 131 | dialog_context = await dialogs.create_context(turn_context) 132 | results = await dialog_context.continue_dialog() 133 | 134 | if results.status == DialogTurnStatus.Empty: 135 | options = PromptOptions( 136 | prompt = Activity( 137 | type = ActivityTypes.message, 138 | text = "test temperature unit api" 139 | ) 140 | ) 141 | await dialog_context.prompt("temperatureprompt", options) 142 | elif results.status == DialogTurnStatus.Complete: 143 | reply = results.result 144 | result = f"temperature : '{reply.value}' and unit : '{reply.unit}'" 145 | await turn_context.send_activity(result) 146 | 147 | await conv_state.save_changes(turn_context) 148 | 149 | adapter = TestAdapter(exec_test) 150 | 151 | conv_state = ConversationState(MemoryStorage()) 152 | 153 | dialog_state = conv_state.create_property("dialog-state") 154 | dialogs = DialogSet(dialog_state) 155 | dialogs.add(NumberWithUnitPrompt("temperatureprompt", NumberWithUnitPromptType.Temperature)) 156 | 157 | step1 = await adapter.test('Hello', 'test temperature unit api') 158 | step2 = await step1.send('Set the temperature to 18 degrees celsius"') 159 | await step2.assert_reply("temperature : '18' and unit : 'C'") -------------------------------------------------------------------------------- /libraries/botbuilder-community-dialogs-prompts/test/test_phone_prompt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pathlib 3 | import pytest 4 | import aiounittest 5 | import asyncio 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("dialogs").joinpath("prompts") 9 | sys.path.append(str(libpath)) 10 | 11 | from botbuilder.dialogs.prompts import ( 12 | AttachmentPrompt, 13 | PromptOptions, 14 | PromptValidatorContext, 15 | ) 16 | 17 | from botbuilder.core import ( 18 | TurnContext, 19 | ConversationState, 20 | MemoryStorage, 21 | MessageFactory, 22 | ) 23 | from botbuilder.schema import Activity, ActivityTypes, Attachment 24 | from botbuilder.core.adapters import TestAdapter 25 | from botbuilder.dialogs import DialogSet, DialogTurnStatus 26 | from phone_prompt import PhoneNumberPrompt 27 | 28 | class PhoneNumberPromptTest(aiounittest.AsyncTestCase): 29 | async def test_phone_prompt(self): 30 | async def exec_test(turn_context:TurnContext): 31 | dialog_context = await dialogs.create_context(turn_context) 32 | 33 | results = await dialog_context.continue_dialog() 34 | if (results.status == DialogTurnStatus.Empty): 35 | options = PromptOptions( 36 | prompt = Activity( 37 | type = ActivityTypes.message, 38 | text = "test the phone number type api" 39 | ) 40 | ) 41 | await dialog_context.prompt("phoneprompt", options) 42 | 43 | elif results.status == DialogTurnStatus.Complete: 44 | reply = results.result 45 | await turn_context.send_activity(reply) 46 | 47 | await conv_state.save_changes(turn_context) 48 | 49 | adapter = TestAdapter(exec_test) 50 | 51 | conv_state = ConversationState(MemoryStorage()) 52 | 53 | dialog_state = conv_state.create_property("dialog-state") 54 | dialogs = DialogSet(dialog_state) 55 | dialogs.add(PhoneNumberPrompt("phoneprompt")) 56 | 57 | step1 = await adapter.test('Hello', 'test the phone number type api') 58 | step2 = await step1.send('My phone number is 1 (877) 609-2233') 59 | await step2.assert_reply("1 (877) 609-2233") -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/README.md: -------------------------------------------------------------------------------- 1 | # Activity Type Middleware 2 | 3 | This middleware package is a Python port of the [C# Activity Type middleware component](https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/tree/develop/libraries/Bot.Builder.Community.Middleware.HandleActivityType) from the Bot Builder Community. It intercepts messages based on the activity type so that you can automatically handle certain types outside of the standard dialog flow. 4 | 5 | ## Installing 6 | 7 | Coming Soon 8 | 9 | ## Usage 10 | 11 | ```python 12 | 13 | from activity_type_middleware import ActivityTypeMiddleware; 14 | 15 | async def turn_adapter_callback(turn_context:TurnContext): 16 | await turn_context.send_activity("Hey activity Middlware") 17 | 18 | activity_adapter.use(ActivityTypeMiddleware(ActivityTypes.message,turn_adapter_callback)) 19 | 20 | ``` 21 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/botbuilder/community/middleware/activity/type/__init__.py: -------------------------------------------------------------------------------- 1 | from .about import __version__ 2 | from .activity_type_middleware import ActivityTypeMiddleware 3 | 4 | __all__ = [ 5 | "ActivityTypeMiddleware", 6 | "__version__" 7 | ] -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/botbuilder/community/middleware/activity/type/about.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __title__ = "botbuilder-community-middleware-activity-type" 4 | __version__ = ( 5 | os.environ["packageVersion"] if "packageVersion" in os.environ else "0.1.0" 6 | ) 7 | __uri__ = "https://github.com/BotBuilderCommunity/botbuilder-community-python" 8 | __author__ = "Bot Builder Community" 9 | __description__ = "Microsoft Bot Builder Community Middleware activity type" 10 | __summary__ = "Bot Framework middleware component to handle incoming activities based on a specific activity type" 11 | __license__ = "MIT" -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/botbuilder/community/middleware/activity/type/activity_type_middleware.py: -------------------------------------------------------------------------------- 1 | from botbuilder.core import Middleware,TurnContext 2 | from botbuilder.schema import Activity,ActivityTypes 3 | from typing import Awaitable,Callable 4 | 5 | class ActivityTypeMiddleware(Middleware): 6 | def __init__(self, 7 | activitytype:ActivityTypes, 8 | callback): 9 | self._activitytype = activitytype 10 | self._callback = callback 11 | 12 | async def on_turn(self, 13 | context:TurnContext, 14 | next:Callable[[TurnContext],Awaitable]): 15 | if self._activitytype == context.activity.type: 16 | await self._callback(context) 17 | await next() 18 | 19 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/requirements.txt: -------------------------------------------------------------------------------- 1 | aiounittest>=1.3.0 2 | botbuilder-core>=4.5.0b5 3 | botbuilder-schema>=4.5.0b5 4 | recognizers_text_suite>=1.0.2a2 -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | REQUIRES = [ 5 | "botbuilder-core>=4.5.0b5", 6 | "botbuilder-schema>=4.5.0b5", 7 | "recognizers_text_suite>=1.0.2a2", 8 | "aiounittest>=1.3.0" 9 | ] 10 | 11 | TESTS_REQUIRES = ["aiounittest>=1.3.0"] 12 | 13 | root = os.path.abspath(os.path.dirname(__file__)) 14 | 15 | with open(os.path.join(root, "botbuilder", "community", "middleware", "activity","type", "about.py")) as f: 16 | package_info = {} 17 | info = f.read() 18 | exec(info, package_info) 19 | 20 | with open(os.path.join(root, "README.md"), encoding="utf-8") as f: 21 | long_description = f.read() 22 | 23 | setup( 24 | name=package_info["__title__"], 25 | version=package_info["__version__"], 26 | url=package_info["__uri__"], 27 | author=package_info["__author__"], 28 | description=package_info["__description__"], 29 | keywords="botbuilder bots ai botframework middleware activity type", 30 | long_description=long_description, 31 | long_description_content_type="text/markdown", 32 | license=package_info["__license__"], 33 | packages=[ 34 | "botbuilder.community.middleware.activity.type", 35 | ], 36 | install_requires=REQUIRES + TESTS_REQUIRES, 37 | tests_require=TESTS_REQUIRES, 38 | include_package_data=True, 39 | classifiers=[ 40 | "Programming Language :: Python :: 3.7", 41 | "Intended Audience :: Developers", 42 | "License :: OSI Approved :: MIT License", 43 | "Operating System :: OS Independent", 44 | "Development Status :: 3 - Alpha", 45 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 46 | ], 47 | ) -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-activity-type/test/test_activity_type_middleware.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pathlib 3 | import sys 4 | import aiounittest 5 | import pytest 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("middleware").joinpath("activity").joinpath("type") 9 | sys.path.append(str(libpath)) 10 | 11 | 12 | from botbuilder.core import MessageFactory, TurnContext 13 | from botbuilder.core.adapters import TestAdapter 14 | from botbuilder.schema import ActivityTypes 15 | from activity_type_middleware import ActivityTypeMiddleware 16 | 17 | class TestActivityMiddleware(aiounittest.AsyncTestCase): 18 | async def test_adapter_middleware(self): 19 | 20 | async def turn_adapter_callback(turn_context:TurnContext): 21 | await turn_context.send_activity("Hey activity Middlware") 22 | 23 | async def exec_test(turn_context:TurnContext): 24 | await turn_context.send_activity("Test activity Middleware") 25 | 26 | activity_adapter = TestAdapter(exec_test) 27 | activity_adapter.use(ActivityTypeMiddleware(ActivityTypes.message,turn_adapter_callback)) 28 | await activity_adapter.test('Hello, activity type bot!', 'Hey activity Middlware') 29 | 30 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/README.md: -------------------------------------------------------------------------------- 1 | # Text Recognizer Middleware 2 | 3 | The Text Recognizer Middleware library is a compliment to the Text Recognizer dialog prompts. These middleware components can be used to identify certain text sequences that you might want to alter prior to appearing on the chat window. For example, turning a URL into an actual link, or turning a hashtag into a link that points to a Twitter search. 4 | 5 | ## Installing 6 | 7 | Coming soon 8 | 9 | ## Usage 10 | 11 | All middleware is created and used in the same way. For example, for social media recognition, import the `SocialMediaRecognizerMiddleware` class from the package, and add it to your bot adapter: 12 | 13 | from social_media_middleware import SocialMediaRecognizerMiddleware 14 | 15 | adapter.use(SocialMediaRecognizerMiddleware()); 16 | 17 | When used, the `turn_state` on the `TurnContext` will have a property named `mentionentities`, which will be an array of strings with the `@` syntax elements. 18 | 19 | Supported middleware classes include: 20 | 21 | | Class | Property/Properties on `turn_state` | 22 | | ---- | ----------- | 23 | | `EmailRecognizerMiddleware` | `context.turn_state.get("emailentities")` | 24 | | `UrlRecognizerMiddleware` | `context.turn_state.get("urlentities")` | 25 | | `PhoneRecognizerMiddleware` | `context.turn_state.get("phonenumberentities")` | 26 | | `SocialMediaRecognizerMiddleware` | `context.turn_state.get("mentionentities")` or `context.turn_state.get("hashentities")` | 27 | 28 | In each case, the `turn_state` of the `TurnContext` contains an array with the various recognized entities. 29 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/__init__.py: -------------------------------------------------------------------------------- 1 | from .about import __version__ 2 | from .email_middleware import EmailRecognizerMiddleware 3 | from .phone_middleware import PhoneRecognizerMiddleware 4 | from .social_media_middleware import SocialMediaRecognizerMiddleware 5 | from .url_middleware import UrlRecognizerMiddleware 6 | 7 | __all__ = [ 8 | "EmailRecognizerMiddleware", 9 | "PhoneRecognizerMiddleware", 10 | "SocialMediaRecognizerMiddleware", 11 | "UrlRecognizerMiddleware", 12 | "__version__" 13 | ] -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/about.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | __title__ = "botbuilder-community-middleware-text-recognizer" 4 | __version__ = ( 5 | os.environ["packageVersion"] if "packageVersion" in os.environ else "0.1.0" 6 | ) 7 | __uri__ = "https://github.com/BotBuilderCommunity/botbuilder-community-python" 8 | __author__ = "Bot Builder Community" 9 | __description__ = "Microsoft Bot Builder Community Middleware test recognizer" 10 | __summary__ = "A collection of Bot Framework middleware components that uses Microsoft's recognizer text suite to parse inbound messages, and extract useful information for Microsoft Bot Builder SDK for Python" 11 | __license__ = "MIT" -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/email_middleware.py: -------------------------------------------------------------------------------- 1 | from recognizers_sequence import SequenceRecognizer 2 | from recognizers_text import Culture,ModelResult 3 | from botbuilder.core import Middleware,TurnContext 4 | from botbuilder.schema import Activity,ActivityTypes 5 | from typing import Callable,Awaitable 6 | 7 | class EmailRecognizerMiddleware(Middleware): 8 | def __init__(self, 9 | default_locale = None): 10 | if default_locale is None: 11 | default_locale = Culture.English 12 | 13 | self._default_locale = default_locale 14 | 15 | async def on_turn(self, 16 | context:TurnContext, 17 | next:Callable[[TurnContext],Awaitable]): 18 | if context.activity.type == ActivityTypes.message: 19 | email_recongnizer = SequenceRecognizer(self._default_locale) 20 | email_model = email_recongnizer.get_email_model() 21 | model_result = email_model.parse(context.activity.text) 22 | 23 | if len(model_result) > 0: 24 | email_entities = [] 25 | for email in model_result: 26 | value = email.resolution["value"] 27 | email_entities.append(value) 28 | context.turn_state.setdefault("emailentities",email_entities) 29 | return await next() -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/phone_middleware.py: -------------------------------------------------------------------------------- 1 | from recognizers_sequence import SequenceRecognizer 2 | from recognizers_text import Culture,ModelResult 3 | from botbuilder.core import Middleware,TurnContext 4 | from botbuilder.schema import Activity,ActivityTypes 5 | from typing import Callable,Awaitable 6 | 7 | class PhoneRecognizerMiddleware(Middleware): 8 | def __init__(self, 9 | default_locale = None): 10 | if default_locale is None: 11 | default_locale = Culture.English 12 | 13 | self._default_locale = default_locale 14 | 15 | async def on_turn(self, 16 | context:TurnContext, 17 | next:Callable[[TurnContext],Awaitable]): 18 | if context.activity.type == ActivityTypes.message: 19 | phone_recongnizer = SequenceRecognizer(self._default_locale) 20 | phone_model = phone_recongnizer.get_phone_number_model() 21 | model_result = phone_model.parse(context.activity.text) 22 | 23 | if len(model_result) > 0: 24 | phonenumber_entities = [] 25 | for phone in model_result: 26 | value = phone.resolution["value"] 27 | phonenumber_entities.append(value) 28 | context.turn_state.setdefault("phonenumberentities",phonenumber_entities) 29 | return await next() -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/social_media_middleware.py: -------------------------------------------------------------------------------- 1 | from recognizers_sequence import SequenceRecognizer 2 | from recognizers_text import Culture,ModelResult 3 | from botbuilder.core import Middleware,TurnContext 4 | from botbuilder.schema import Activity,ActivityTypes 5 | from typing import Callable,Awaitable 6 | 7 | class SocialMediaRecognizerMiddleware(Middleware): 8 | def __init__(self, 9 | default_locale = None): 10 | if default_locale is None: 11 | default_locale = Culture.English 12 | 13 | self._default_locale = default_locale 14 | 15 | async def on_turn(self, 16 | context:TurnContext, 17 | next:Callable[[TurnContext],Awaitable]): 18 | if context.activity.type == ActivityTypes.message: 19 | social_recongnizer = SequenceRecognizer(self._default_locale) 20 | mention_model = social_recongnizer.get_mention_model() 21 | model_result = mention_model.parse(context.activity.text) 22 | 23 | if len(model_result) > 0: 24 | mention_entities = [] 25 | for mention in model_result: 26 | value = mention.resolution["value"] 27 | mention_entities.append(value) 28 | context.turn_state.setdefault("mentionentities",mention_entities) 29 | 30 | hash_model = social_recongnizer.get_hashtag_model() 31 | model_result = hash_model.parse(context.activity.text) 32 | 33 | if len(model_result) > 0: 34 | hash_entities = [] 35 | for hashmodel in model_result: 36 | value = hashmodel.resolution["value"] 37 | hash_entities.append(value) 38 | context.turn_state.setdefault("hashentities",hash_entities) 39 | 40 | return await next() -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/botbuilder/community/middleware/text/recognizer/url_middleware.py: -------------------------------------------------------------------------------- 1 | from recognizers_sequence import SequenceRecognizer 2 | from recognizers_text import Culture,ModelResult 3 | from botbuilder.core import Middleware,TurnContext 4 | from botbuilder.schema import Activity,ActivityTypes 5 | from typing import Callable,Awaitable 6 | 7 | class UrlRecognizerMiddleware(Middleware): 8 | def __init__(self, 9 | default_locale = None): 10 | if default_locale is None: 11 | default_locale = Culture.English 12 | 13 | self._default_locale = default_locale 14 | 15 | async def on_turn(self, 16 | context:TurnContext, 17 | next:Callable[[TurnContext],Awaitable]): 18 | if context.activity.type == ActivityTypes.message: 19 | url_recongnizer = SequenceRecognizer(self._default_locale) 20 | url_model = url_recongnizer.get_url_model() 21 | model_result = url_model.parse(context.activity.text) 22 | 23 | if len(model_result) > 0: 24 | url_entities = [] 25 | for url in model_result: 26 | value = url.resolution["value"] 27 | url_entities.append(value) 28 | context.turn_state.setdefault("urlentities",url_entities) 29 | return await next() -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/requirements.txt: -------------------------------------------------------------------------------- 1 | aiounittest>=1.3.0 2 | botbuilder-core>=4.5.0b5 3 | botbuilder-schema>=4.5.0b5 4 | recognizers_text_suite>=1.0.2a2 -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | REQUIRES = [ 5 | "botbuilder-core>=4.5.0b5", 6 | "botbuilder-schema>=4.5.0b5", 7 | "recognizers_text_suite>=1.0.2a2", 8 | "aiounittest>=1.3.0" 9 | ] 10 | 11 | TESTS_REQUIRES = ["aiounittest>=1.3.0"] 12 | 13 | root = os.path.abspath(os.path.dirname(__file__)) 14 | 15 | with open(os.path.join(root, "botbuilder", "community", "middleware", "text","recognizer", "about.py")) as f: 16 | package_info = {} 17 | info = f.read() 18 | exec(info, package_info) 19 | 20 | with open(os.path.join(root, "README.md"), encoding="utf-8") as f: 21 | long_description = f.read() 22 | 23 | setup( 24 | name=package_info["__title__"], 25 | version=package_info["__version__"], 26 | url=package_info["__uri__"], 27 | author=package_info["__author__"], 28 | description=package_info["__description__"], 29 | keywords="botbuilder bots ai botframework middleware text recognizer", 30 | long_description=long_description, 31 | long_description_content_type="text/markdown", 32 | license=package_info["__license__"], 33 | packages=[ 34 | "botbuilder.community.middleware.text.recognizer", 35 | ], 36 | install_requires=REQUIRES + TESTS_REQUIRES, 37 | tests_require=TESTS_REQUIRES, 38 | include_package_data=True, 39 | classifiers=[ 40 | "Programming Language :: Python :: 3.7", 41 | "Intended Audience :: Developers", 42 | "License :: OSI Approved :: MIT License", 43 | "Operating System :: OS Independent", 44 | "Development Status :: 3 - Alpha", 45 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 46 | ], 47 | ) -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/test/test_email_middleware.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pathlib 3 | import sys 4 | import aiounittest 5 | import pytest 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | print(current) 9 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("middleware").joinpath("text").joinpath("recognizer") 10 | sys.path.append(str(libpath)) 11 | 12 | 13 | from botbuilder.core import MessageFactory, TurnContext 14 | from botbuilder.core.adapters import TestAdapter 15 | from email_middleware import EmailRecognizerMiddleware 16 | 17 | class EmailMiddleware(aiounittest.AsyncTestCase): 18 | async def test_email_prompt(self): 19 | async def exec_test(turn_context:TurnContext): 20 | item = turn_context.turn_state.get('emailentities') 21 | text = MessageFactory.text(item[0]) 22 | await turn_context.send_activity(text) 23 | 24 | email_reg_middleware = EmailRecognizerMiddleware() 25 | email_adapter = TestAdapter(exec_test) 26 | email_adapter.use(email_reg_middleware) 27 | await email_adapter.test('My mail address is r.vinoth@live.com', 'r.vinoth@live.com') 28 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/test/test_phone_middleware.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pathlib 3 | import sys 4 | import aiounittest 5 | import pytest 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("middleware").joinpath("text").joinpath("recognizer") 9 | sys.path.append(str(libpath)) 10 | 11 | 12 | from botbuilder.core import MessageFactory, TurnContext 13 | from botbuilder.core.adapters import TestAdapter 14 | from phone_middleware import PhoneRecognizerMiddleware 15 | 16 | class PhoneNumberMiddleware(aiounittest.AsyncTestCase): 17 | async def test_phone_prompt(self): 18 | async def exec_test(turn_context:TurnContext): 19 | item = turn_context.turn_state.get('phonenumberentities') 20 | text = MessageFactory.text(item[0]) 21 | await turn_context.send_activity(text) 22 | 23 | phone_reg_middle = PhoneRecognizerMiddleware() 24 | phone_adapter = TestAdapter(exec_test) 25 | phone_adapter.use(phone_reg_middle) 26 | await phone_adapter.test('My phone number is 540-123-4321', '540-123-4321') 27 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/test/test_social_middleware.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pathlib 3 | import sys 4 | import aiounittest 5 | import pytest 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("middleware").joinpath("text").joinpath("recognizer") 9 | sys.path.append(str(libpath)) 10 | 11 | 12 | from botbuilder.core import MessageFactory, TurnContext 13 | from botbuilder.core.adapters import TestAdapter 14 | from social_media_middleware import SocialMediaRecognizerMiddleware 15 | 16 | class SocialMiddleware(aiounittest.AsyncTestCase): 17 | async def test_mention_prompt(self): 18 | async def exec_test(turn_context:TurnContext): 19 | item = turn_context.turn_state.get('mentionentities') 20 | text = MessageFactory.text(item[0]) 21 | await turn_context.send_activity(text) 22 | 23 | social_adapter = TestAdapter(exec_test) 24 | social_adapter.use(SocialMediaRecognizerMiddleware()) 25 | await social_adapter.test('My Twitter handle is @vinothrajendran', '@vinothrajendran') 26 | 27 | async def test_hash_prompt(self): 28 | async def exec_test(turn_context:TurnContext): 29 | item = turn_context.turn_state.get('hashentities') 30 | text = MessageFactory.text(item[0]) 31 | await turn_context.send_activity(text) 32 | 33 | social_adapter = TestAdapter(exec_test) 34 | social_adapter.use(SocialMediaRecognizerMiddleware()) 35 | await social_adapter.test('Follow the #botframework hashtag', '#botframework') 36 | -------------------------------------------------------------------------------- /libraries/botbuilder-community-middleware-text-recognizer/test/test_url_middleware.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import pathlib 3 | import sys 4 | import aiounittest 5 | import pytest 6 | 7 | current = pathlib.Path(__file__).parent.parent 8 | libpath = current.joinpath("botbuilder").joinpath("community").joinpath("middleware").joinpath("text").joinpath("recognizer") 9 | sys.path.append(str(libpath)) 10 | 11 | 12 | from botbuilder.core import MessageFactory, TurnContext 13 | from botbuilder.core.adapters import TestAdapter 14 | from url_middleware import UrlRecognizerMiddleware 15 | 16 | class URLMiddleware(aiounittest.AsyncTestCase): 17 | async def test_url_prompt(self): 18 | async def exec_test(turn_context:TurnContext): 19 | item = turn_context.turn_state.get('urlentities') 20 | text = MessageFactory.text(item[0]) 21 | await turn_context.send_activity(text) 22 | 23 | url_reg_middleware = UrlRecognizerMiddleware() 24 | url_adapter = TestAdapter(exec_test) 25 | url_adapter.use(url_reg_middleware) 26 | await url_adapter.test('My web site is https://rvinothrajendran.github.io/', 'https://rvinothrajendran.github.io/') 27 | --------------------------------------------------------------------------------