10000 initial commit for botbuilder.dialogs.choices · rsliang/botbuilder-python@df226ce · GitHub
[go: up one dir, main page]

Skip to content

Commit df226ce

Browse files
committed
initial commit for botbuilder.dialogs.choices
1 parent 62b0512 commit df226ce

File tree

13 files changed

+767
-0
lines changed

13 files changed

+767
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
# --------------------------------------------------------------------------
7+
8+
from .about import __version__
9+
10+
from .choices import (Channel, Tokenizer,
11+
TokenizerFunction, Token,
12+
Choice, FindChoicesOptions,
13+
ModelResult, FoundValue,
14+
SortedValue, Find,
15+
FindValuesOptions)
16+
17+
__all__ = ['Channel', 'Choice', 'FindChoicesOptions', 'ModelResult', 'Tokenizer', 'TokenizerFunction',
18+
'Token', 'FoundValue', 'SortedValue', 'Find', 'FindValuesOptions', '__version__']
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
__title__ = 'botbuilder-dialogs'
5+
__version__ = '4.0.0.a4'
6+
__uri__ = 'https://www.github.com/Microsoft/botbuilder-python'
7+
__author__ = 'Microsoft'
8+
__description__ = 'Microsoft Bot Framework Bot Builder'
9+
__summary__ = 'Microsoft Bot Framework Bot Builder SDK for Python.'
10+
__license__ = 'MIT'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
# --------------------------------------------------------------------------
7+
8+
from .channel import Channel
9+
from .tokenizer import Tokenizer, TokenizerFunction, Token
10+
from .choices import Choice, FoundChoice
11+
from .model_result import ModelResult
12+
from .find import Find, FindValuesOptions, FindChoicesOptions
13+
from .values import FoundValue, SortedValue
14+
15+
__all__ = ['Channel', 'Choice', 'FoundChoice',
16+
'FindChoicesOptions', 'ModelResult', 'Tokenizer',
17+
'TokenizerFunction', 'Token', 'FoundValue',
18+
'SortedValue', 'Find', 'FindValuesOptions']
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from botbuilder.core import BotContext
5+
6+
7+
class Channels:
8+
"""INTERNAL: Accessible through the Channel class via `Channel.channels`."""
9+
facebook = 'facebook'
10+
skype = 'skype'
11+
msteams = 'msteams'
12+
telegram = 'telegram'
13+
kik = 'kik'
14+
email = 'email'
15+
slack = 'slack'
16+
groupme = 'groupme'
17+
sms = 'sms'
18+
emulator = 'emulator'
19+
directline = 'directline'
20+
webchat = 'webchat'
21+
console = 'console'
22+
cortana = 'cortana'
23+
24+
25+
class Channel:
26+
channels = Channels
27+
28+
@staticmethod
29+
def supports_suggested_actions(channel_id: str, button_count: int = 100) -> bool:
30+
"""
31+
Checks if a Bot Framework supported channel supports a certain number of suggestedActions.
32+
:param channel_id:
33+
:param button_count:
34+
:return:
35+
"""
36+
if hasattr(Channels, channel_id):
37+
if channel_id == Channels.facebook or channel_id == Channels.skype:
38+
return button_count <= 10
39+
if channel_id == Channels.kik:
40+
return button_count <= 20
41+
if channel_id == Channels.slack or channel_id == Channels.telegram or channel_id == Channels.emulator:
42+
return button_count <= 100
43+
else:
44+
return False
45+
46+
@staticmethod
47+
def supports_card_actions(channel_id: str, button_count: int = 100) -> bool:
48+
"""
49+
Checks if a Bot Framework supported channel supports a certain number of card actions.
50+
:param channel_id:
51+
:param button_count:
52+
:return:
53+
"""
54+
if hasattr(Channels, channel_id):
55+
if channel_id == Channels.facebook or channel_id == Channels.skype or channel_id == Channels.msteams:
56+
return button_count <= 3
57+
if (channel_id == Channels.slack or channel_id == Channels.directline or channel_id == Channels.emulator or
58+
channel_id == Channels.webchat or channel_id == Channels.cortana):
59+
return button_count <= 100
60+
else:
61+
return False
62+
63+
@staticmethod
64+
def has_message_feed(channel_id: str) -> bool:
65+
"""
66+
:param channel_id:
67+
:return:
68+
"""
69+
if channel_id == Channels.cortana:
70+
return False
71+
else:
72+
return True
73+
74+
@staticmethod
75+
def max_action_title_length(channel_id: str) -> int:
76+
"""
77+
:param channel_id:
78+
:return:
79+
"""
80+
return 20
81+
82+
@staticmethod
83+
def get_channel_id(context: BotContext) -> str:
84+
"""
85+
:param context:
86+
:return:
87+
"""
88+
return context.activity.channel_id
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from typing import List
5+
from botbuilder.schema import CardAction
6+
7+
8+
class Choice:
9+
def __init__(self, value: str, action: CardAction = None, synonyms: List[str] = None):
10+
"""An instance of a choice that can be used to render a choice to a user or recognize something a
11+
user picked.
12+
:param value:
13+
:param action:
14+
:param synonyms:
15+
"""
16+
17+
"""Value to return when recognized by "find_choices()".
18+
Will also be used to render choices to the user if no action is provided."""
19+
self.value = value
20+
21+
"""(Optional) action to use when rendering the choice as a suggested action. This **MUST**
22+
be a complete action containing `type`, `title`, and `value` fields. If not specified an
23+
`imBack` action will be generated based on the choices value field. """
24+
self.action = action
25+
26+
"""(Optional) list of synonyms to recognize in addition to the value and
27+
action fields."""
28+
self.synonyms = synonyms
29+
30+
31+
class FoundChoice:
32+
def __init__(self, value: str, index: int, score: float, synonym: str=None):
33+
"""Result returned by `find_choices()`.
34+
:param value:
35+
:param index:
36+
:param score:
37+
:param synonym:
38+
"""
39+
40+
"""The value of the choice that was matched."""
41+
self.value = value
42+
43+
"""The choices index within the list of choices that was searched over."""
44+
self.index = index
45+
46+
"""The accuracy with which the synonym matched the specified portion of the utterance.
47+
A value of 1.0 would indicate a perfect match."""
48+
self.score = score
49+
50+
"""(Optional) The synonym that was matched."""
51+
self.synonym = synonym

0 commit comments

Comments
 (0)
0