We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
date_resolver_dialog - test of "definite"
## Version SDK v4.5.0b3
in botbuilder-python/samples/13.core-bot/dialogs/date_resolver_dialog.py

## Describe the bug
Line : _if "definite" in Timex(timex).types:_
The goal of this line is to treat ambiguous date such as timex date = XXXX-05-17
so the test must be "not in" instead of "in" ("definite" = type for an unambiguous date)

[bug]


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `samples/13.core-bot/dialogs/date_resolver_dialog.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3 
4 from botbuilder.core import MessageFactory
5 from botbuilder.dialogs import WaterfallDialog, DialogTurnResult, WaterfallStepContext
6 from botbuilder.dialogs.prompts import (
7     DateTimePrompt,
8     PromptValidatorContext,
9     PromptOptions,
10     DateTimeResolution,
11 )
12 from botbuilder.schema import InputHints
13 from .cancel_and_help_dialog import CancelAndHelpDialog
14 
15 from datatypes_date_time.timex import Timex
16 
17 
18 class DateResolverDialog(CancelAndHelpDialog):
19     def __init__(self, dialog_id: str = None):
20         super(DateResolverDialog, self).__init__(
21             dialog_id or DateResolverDialog.__name__
22         )
23 
24         self.add_dialog(
25             DateTimePrompt(
26                 DateTimePrompt.__name__, DateResolverDialog.datetime_prompt_validator
27             )
28         )
29         self.add_dialog(
30             WaterfallDialog(
31                 WaterfallDialog.__name__ + "2", [self.initial_step, self.final_step]
32             )
33         )
34 
35         self.initial_dialog_id = WaterfallDialog.__name__ + "2"
36 
37     async def initial_step(
38         self, step_context: WaterfallStepContext
39     ) -> DialogTurnResult:
40         timex = step_context.options
41 
42         prompt_msg_text = "On what date would you like to travel?"
43         prompt_msg = MessageFactory.text(
44             prompt_msg_text, prompt_msg_text, InputHints.expecting_input
45         )
46 
47         reprompt_msg_text = "I'm sorry, for best results, please enter your travel date including the month, day and year."
48         reprompt_msg = MessageFactory.text(
49             reprompt_msg_text, reprompt_msg_text, InputHints.expecting_input
50         )
51 
52         if timex is None:
53             # We were not given any date at all so prompt the user.
54             return await step_context.prompt(
55                 DateTimePrompt.__name__,
56                 PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),
57             )
58         # We have a Date we just need to check it is unambiguous.
59         if "definite" in Timex(timex).types:
60             # This is essentially a "reprompt" of the data we were given up front.
61             return await step_context.prompt(
62                 DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)
63             )
64 
65         return await step_context.next(DateTimeResolution(timex=timex))
66 
67     async def final_step(self, step_context: WaterfallStepContext):
68         timex = step_context.result[0].timex
69         return await step_context.end_dialog(timex)
70 
71     @staticmethod
72     async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
73         if prompt_context.recognized.succeeded:
74             timex = prompt_context.recognized.value[0].timex.split("T")[0]
75 
76             # TODO: Needs TimexProperty
77             return "definite" in Timex(timex).types
78 
79         return False
80
```

Path: `samples/13.core-bot/dialogs/main_dialog.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3 
4 from datetime import datetime
5 from typing import Dict
6 from botbuilder.dialogs import (
7     ComponentDialog,
8     DialogSet,
9     DialogTurnStatus,
10     WaterfallDialog,
11     WaterfallStepContext,
12     DialogTurnResult,
13 )
14 from botbuilder.dialogs.prompts import TextPrompt, ConfirmPrompt, PromptOptions
15 from botbuilder.core import MessageFactory, TurnContext
16 from botbuilder.schema import InputHints
17 
18 from .booking_dialog import BookingDialog
19 from booking_details import BookingDetails
20 from flight_booking_recognizer import FlightBookingRecognizer
21 from helpers.luis_helper import LuisHelper, Intent
22 
23 
24 class MainDialog(ComponentDialog):
25     def __init__(
26         self, luis_recognizer: FlightBookingRecognizer, booking_dialog: BookingDialog
27     ):
28         super(MainDialog, self).__init__(MainDialog.__name__)
29 
30         self._luis_recognizer = luis_recognizer
31         self._booking_dialog_id = booking_dialog.id
32 
33         self.add_dialog(TextPrompt(TextPrompt.__name__))
34         self.add_dialog(booking_dialog)
35         self.add_dialog(
36             WaterfallDialog(
37                 "WFDialog", [self.intro_step, self.act_step, self.final_step]
38             )
39         )
40 
41         self.initial_dialog_id = "WFDialog"
42 
43     async def intro_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
44         if not self._luis_recognizer.is_configured:
45             await step_context.context.send_activity(
46                 MessageFactory.text(
47                     "NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and "
48                     "'LuisAPIHostName' to the appsettings.json file.",
49                     input_hint=InputHints.ignoring_input,
50                 )
51             )
52 
53             return await step_context.next(None)
54         message_text = (
55             str(step_context.options)
56             if step_context.options
57             else "What can I help you with today?"
58         )
59         prompt_message = MessageFactory.text(
60             message_text, message_text, InputHints.expecting_input
61         )
62 
63         return await step_context.prompt(
64             TextPrompt.__name__, PromptOptions(prompt=prompt_message)
65         )
66 
67     async def act_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
68         if not self._luis_recognizer.is_configured:
69             # LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.
70             return await step_context.begin_dialog(
71                 self._booking_dialog_id, BookingDetails()
72             )
73 
74         # Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
75         intent, luis_result = await LuisHelper.execute_luis_query(
76             self._luis_recognizer, step_context.context
77         )
78 
79         # top_intent = cognitive_models_helper.top_intent(luis_result['intents'])
80 
81         if intent == Intent.BOOK_FLIGHT.value and luis_result:
82             await MainDialog._show_warning_for_unsupported_cities(
83                 step_context.context, luis_result
84             )
85 
86             # Run the BookingDialog giving it whatever details we have from the LUIS call.
87             return await step_context.begin_dialog(self._booking_dialog_id, luis_result)
88 
89         elif intent == Intent.GET_WEATHER.value:
90             get_weather_text = "TODO: get weather flow here"
91             get_weather_message = MessageFactory.text(
92                 get_weather_text, get_weather_text, InputHints.ignoring_input
93             )
94             await step_context.context.send_activity(get_weather_message)
95 
96         else:
97             didnt_understand_text = (
98                 "Sorry, I didn't get that. Please try asking in a different way"
99             )
100             didnt_understand_message = MessageFactory.text(
101                 didnt_understand_text, didnt_understand_text, InputHints.ignoring_input
102             )
103             await step_context.context.send_activity(didnt_understand_message)
104 
105         return await step_context.next(None)
106 
107     async def final_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:
108         # If the child dialog ("BookingDialog") was cancelled or the user failed to confirm,
109         # the Result here will be null.
110         if step_context.result is not None:
111             result = step_context.result
112 
113             # Now we have all the booking details call the booking service.
114 
115             # If the call to the booking service was successful tell the user.
116             # time_property = Timex(result.travel_date)
117             # travel_date_msg = time_property.to_natural_language(datetime.now())
118             msg_txt = f"I have you booked to {result.destination} from {result.origin} on {result.travel_date}"
119             message = MessageFactory.text(msg_txt, msg_txt, InputHints.ignoring_input)
120             await step_context.context.send_activity(message)
121 
122         prompt_message = "What else can I do for you?"
123         return await step_context.replace_dialog(self.id, prompt_message)
124 
125     @staticmethod
126     async def _show_warning_for_unsupported_cities(
127         context: TurnContext, luis_result: BookingDetails
128     ) -> None:
129         if luis_result.unsupported_airports:
130             message_text = (
131                 f"Sorry but the following airports are not supported:"
132                 f" {', '.join(luis_result.unsupported_airports)}"
133             )
134             message = MessageFactory.text(
135                 message_text, message_text, InputHints.ignoring_input
136             )
137             await context.send_activity(message)
138
```

Path: `samples/13.core-bot/helpers/luis_helper.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3 from enum import Enum
4 from typing import Dict
5 from botbuilder.ai.luis import LuisRecognizer, LuisApplication
6 from botbuilder.core import IntentScore, TopIntent, TurnContext
7 
8 from booking_details import BookingDetails
9 
10 
11 class Intent(Enum):
12     BOOK_FLIGHT = "BookFlight"
13     CANCEL = "Cancel"
14     GET_WEATHER = "GetWeather"
15     NONE_INTENT = "NoneIntent"
16 
17 
18 def top_intent(intents: Dict[Intent, dict]) -> TopIntent:
19     max_intent = Intent.NONE_INTENT
20     max_value = 0.0
21 
22     for intent, value in intents:
23         intent_score = IntentScore(value)
24         if intent_score.score > max_value:
25             max_intent, max_value = intent, intent_score.score
26 
27     return TopIntent(max_intent, max_value)
28 
29 
30 class LuisHelper:
31     @staticmethod
32     async def execute_luis_query(
33         luis_recognizer: LuisRecognizer, turn_context: TurnContext
34     ) -> (Intent, object):
35         result = None
36         intent = None
37 
38         try:
39             recognizer_result = await luis_recognizer.recognize(turn_context)
40 
41             intent = (
42                 sorted(
43                     recognizer_result.intents,
44                     key=recognizer_result.intents.get,
45                     reverse=True,
46                 )[:1][0]
47                 if recognizer_result.intents
48                 else None
49             )
50 
51             if intent == Intent.BOOK_FLIGHT.value:
52                 result = BookingDetails()
53 
54                 # We need to get the result from the LUIS JSON which at every level returns an array.
55                 to_entities = recognizer_result.entities.get("$instance", {}).get(
56                     "To", []
57                 )
58                 if len(to_entities) > 0:
59                     if recognizer_result.entities.get("To", [{"$instance": {}}])[0][
60                         "$instance"
61                     ]:
62                         result.destination = to_entities[0]["text"].capitalize()
63                     else:
64                         result.unsupported_airports.append(
65                             to_entities[0]["text"].capitalize()
66                         )
67 
68                 from_entities = recognizer_result.entities.get("$instance", {}).get(
69                     "From", []
70                 )
71                 if len(from_entities) > 0:
72                     if recognizer_result.entities.get("From", [{"$instance": {}}])[0][
73                         "$instance"
74                     ]:
75                         result.origin = from_entities[0]["text"].capitalize()
76                     else:
77                         result.unsupported_airports.append(
78                             from_entities[0]["text"].capitalize()
79                         )
80 
81                 # TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
82                 # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
83                 date_entities = recognizer_result.entities.get("$instance", {}).get(
84                     "datetime", []
85                 )
86                 if len(date_entities) > 0:
87                     result.travel_date = None  # TODO: Set when we get a timex format
88         except Exception as e:
89             print(e)
90 
91         return intent, result
92
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/samples/13.core-bot/dialogs/date_resolver_dialog.py b/samples/13.core-bot/dialogs/date_resolver_dialog.py
--- a/samples/13.core-bot/dialogs/date_resolver_dialog.py
+++ b/samples/13.core-bot/dialogs/date_resolver_dialog.py
@@ -56,7 +56,7 @@
                 PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),
             )
         # We have a Date we just need to check it is unambiguous.
-        if "definite" in Timex(timex).types:
+        if "definite" not in Timex(timex).types:
             # This is essentially a "reprompt" of the data we were given up front.
             return await step_context.prompt(
                 DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)
diff --git a/samples/13.core-bot/dialogs/main_dialog.py b/samples/13.core-bot/dialogs/main_dialog.py
--- a/samples/13.core-bot/dialogs/main_dialog.py
+++ b/samples/13.core-bot/dialogs/main_dialog.py
@@ -1,17 +1,13 @@
 # Copyright (c) Microsoft Corporation. All rights reserved.
 # Licensed under the MIT License.
 
-from datetime import datetime
-from typing import Dict
 from botbuilder.dialogs import (
     ComponentDialog,
-    DialogSet,
-    DialogTurnStatus,
     WaterfallDialog,
     WaterfallStepContext,
     DialogTurnResult,
 )
-from botbuilder.dialogs.prompts import TextPrompt, ConfirmPrompt, PromptOptions
+from botbuilder.dialogs.prompts import TextPrompt, PromptOptions
 from botbuilder.core import MessageFactory, TurnContext
 from botbuilder.schema import InputHints
 
@@ -76,9 +72,8 @@
             self._luis_recognizer, step_context.context
         )
 
-        # top_intent = cognitive_models_helper.top_intent(luis_result['intents'])
-
         if intent == Intent.BOOK_FLIGHT.value and luis_result:
+            # Show a warning for Origin and Destination if we can't resolve them.
             await MainDialog._show_warning_for_unsupported_cities(
                 step_context.context, luis_result
             )
diff --git a/samples/13.core-bot/helpers/luis_helper.py b/samples/13.core-bot/helpers/luis_helper.py
--- a/samples/13.core-bot/helpers/luis_helper.py
+++ b/samples/13.core-bot/helpers/luis_helper.py
@@ -2,7 +2,7 @@
 # Licensed under the MIT License.
 from enum import Enum
 from typing import Dict
-from botbuilder.ai.luis import LuisRecognizer, LuisApplication
+from botbuilder.ai.luis import LuisRecognizer
 from botbuilder.core import IntentScore, TopIntent, TurnContext
 
 from booking_details import BookingDetails
@@ -32,6 +32,9 @@
     async def execute_luis_query(
         luis_recognizer: LuisRecognizer, turn_context: TurnContext
     ) -> (Intent, object):
+        """
+        Returns an object with preformatted LUIS results for the bot's dialogs to consume.
+        """
         result = None
         intent = None
 
@@ -78,13 +81,20 @@
                             from_entities[0]["text"].capitalize()
                         )
 
-                # TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
+                # This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
                 # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
-                date_entities = recognizer_result.entities.get("$instance", {}).get(
-                    "datetime", []
-                )
-                if len(date_entities) > 0:
-                    result.travel_date = None  # TODO: Set when we get a timex format
+                date_entities = recognizer_result.entities.get("datetime", [])
+                if date_entities:
+                    timex = date_entities[0]["timex"]
+
+                    if timex:
+                        datetime = timex[0].split("T")[0]
+
+                        result.travel_date = datetime
+
+                else:
+                    result.travel_date = None
+
         except Exception as e:
             print(e)

{"golden_diff": "diff --git a/samples/13.core-bot/dialogs/date_resolver_dialog.py b/samples/13.core-bot/dialogs/date_resolver_dialog.py\n--- a/samples/13.core-bot/dialogs/date_resolver_dialog.py\n+++ b/samples/13.core-bot/dialogs/date_resolver_dialog.py\n@@ -56,7 +56,7 @@\n                 PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),\n             )\n         # We have a Date we just need to check it is unambiguous.\n-        if \"definite\" in Timex(timex).types:\n+        if \"definite\" not in Timex(timex).types:\n             # This is essentially a \"reprompt\" of the data we were given up front.\n             return await step_context.prompt(\n                 DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)\ndiff --git a/samples/13.core-bot/dialogs/main_dialog.py b/samples/13.core-bot/dialogs/main_dialog.py\n--- a/samples/13.core-bot/dialogs/main_dialog.py\n+++ b/samples/13.core-bot/dialogs/main_dialog.py\n@@ -1,17 +1,13 @@\n # Copyright (c) Microsoft Corporation. All rights reserved.\n # Licensed under the MIT License.\n \n-from datetime import datetime\n-from typing import Dict\n from botbuilder.dialogs import (\n     ComponentDialog,\n-    DialogSet,\n-    DialogTurnStatus,\n     WaterfallDialog,\n     WaterfallStepContext,\n     DialogTurnResult,\n )\n-from botbuilder.dialogs.prompts import TextPrompt, ConfirmPrompt, PromptOptions\n+from botbuilder.dialogs.prompts import TextPrompt, PromptOptions\n from botbuilder.core import MessageFactory, TurnContext\n from botbuilder.schema import InputHints\n \n@@ -76,9 +72,8 @@\n             self._luis_recognizer, step_context.context\n         )\n \n-        # top_intent = cognitive_models_helper.top_intent(luis_result['intents'])\n-\n         if intent == Intent.BOOK_FLIGHT.value and luis_result:\n+            # Show a warning for Origin and Destination if we can't resolve them.\n             await MainDialog._show_warning_for_unsupported_cities(\n                 step_context.context, luis_result\n             )\ndiff --git a/samples/13.core-bot/helpers/luis_helper.py b/samples/13.core-bot/helpers/luis_helper.py\n--- a/samples/13.core-bot/helpers/luis_helper.py\n+++ b/samples/13.core-bot/helpers/luis_helper.py\n@@ -2,7 +2,7 @@\n # Licensed under the MIT License.\n from enum import Enum\n from typing import Dict\n-from botbuilder.ai.luis import LuisRecognizer, LuisApplication\n+from botbuilder.ai.luis import LuisRecognizer\n from botbuilder.core import IntentScore, TopIntent, TurnContext\n \n from booking_details import BookingDetails\n@@ -32,6 +32,9 @@\n     async def execute_luis_query(\n         luis_recognizer: LuisRecognizer, turn_context: TurnContext\n     ) -> (Intent, object):\n+        \"\"\"\n+        Returns an object with preformatted LUIS results for the bot's dialogs to consume.\n+        \"\"\"\n         result = None\n         intent = None\n \n@@ -78,13 +81,20 @@\n                             from_entities[0][\"text\"].capitalize()\n                         )\n \n-                # TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.\n+                # This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.\n                 # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.\n-                date_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n-                    \"datetime\", []\n-                )\n-                if len(date_entities) > 0:\n-                    result.travel_date = None  # TODO: Set when we get a timex format\n+                date_entities = recognizer_result.entities.get(\"datetime\", [])\n+                if date_entities:\n+                    timex = date_entities[0][\"timex\"]\n+\n+                    if timex:\n+                        datetime = timex[0].split(\"T\")[0]\n+\n+                        result.travel_date = datetime\n+\n+                else:\n+                    result.travel_date = None\n+\n         except Exception as e:\n             print(e)\n", "issue": "date_resolver_dialog - test of \"definite\"\n## Version SDK v4.5.0b3\r\nin botbuilder-python/samples/13.core-bot/dialogs/date_resolver_dialog.py\r\n\r\n## Describe the bug\r\nLine : _if \"definite\" in Timex(timex).types:_\r\nThe goal of this line is to treat ambiguous date such as timex date = XXXX-05-17\r\nso the test must be \"not in\" instead of \"in\" (\"definite\" = type for an unambiguous date)\r\n\r\n[bug]\r\n\n", "before_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\nfrom botbuilder.core import MessageFactory\nfrom botbuilder.dialogs import WaterfallDialog, DialogTurnResult, WaterfallStepContext\nfrom botbuilder.dialogs.prompts import (\n    DateTimePrompt,\n    PromptValidatorContext,\n    PromptOptions,\n    DateTimeResolution,\n)\nfrom botbuilder.schema import InputHints\nfrom .cancel_and_help_dialog import CancelAndHelpDialog\n\nfrom datatypes_date_time.timex import Timex\n\n\nclass DateResolverDialog(CancelAndHelpDialog):\n    def __init__(self, dialog_id: str = None):\n        super(DateResolverDialog, self).__init__(\n            dialog_id or DateResolverDialog.__name__\n        )\n\n        self.add_dialog(\n            DateTimePrompt(\n                DateTimePrompt.__name__, DateResolverDialog.datetime_prompt_validator\n            )\n        )\n        self.add_dialog(\n            WaterfallDialog(\n                WaterfallDialog.__name__ + \"2\", [self.initial_step, self.final_step]\n            )\n        )\n\n        self.initial_dialog_id = WaterfallDialog.__name__ + \"2\"\n\n    async def initial_step(\n        self, step_context: WaterfallStepContext\n    ) -> DialogTurnResult:\n        timex = step_context.options\n\n        prompt_msg_text = \"On what date would you like to travel?\"\n        prompt_msg = MessageFactory.text(\n            prompt_msg_text, prompt_msg_text, InputHints.expecting_input\n        )\n\n        reprompt_msg_text = \"I'm sorry, for best results, please enter your travel date including the month, day and year.\"\n        reprompt_msg = MessageFactory.text(\n            reprompt_msg_text, reprompt_msg_text, InputHints.expecting_input\n        )\n\n        if timex is None:\n            # We were not given any date at all so prompt the user.\n            return await step_context.prompt(\n                DateTimePrompt.__name__,\n                PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),\n            )\n        # We have a Date we just need to check it is unambiguous.\n        if \"definite\" in Timex(timex).types:\n            # This is essentially a \"reprompt\" of the data we were given up front.\n            return await step_context.prompt(\n                DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)\n            )\n\n        return await step_context.next(DateTimeResolution(timex=timex))\n\n    async def final_step(self, step_context: WaterfallStepContext):\n        timex = step_context.result[0].timex\n        return await step_context.end_dialog(timex)\n\n    @staticmethod\n    async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:\n        if prompt_context.recognized.succeeded:\n            timex = prompt_context.recognized.value[0].timex.split(\"T\")[0]\n\n            # TODO: Needs TimexProperty\n            return \"definite\" in Timex(timex).types\n\n        return False\n", "path": "samples/13.core-bot/dialogs/date_resolver_dialog.py"}, {"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\nfrom datetime import datetime\nfrom typing import Dict\nfrom botbuilder.dialogs import (\n    ComponentDialog,\n    DialogSet,\n    DialogTurnStatus,\n    WaterfallDialog,\n    WaterfallStepContext,\n    DialogTurnResult,\n)\nfrom botbuilder.dialogs.prompts import TextPrompt, ConfirmPrompt, PromptOptions\nfrom botbuilder.core import MessageFactory, TurnContext\nfrom botbuilder.schema import InputHints\n\nfrom .booking_dialog import BookingDialog\nfrom booking_details import BookingDetails\nfrom flight_booking_recognizer import FlightBookingRecognizer\nfrom helpers.luis_helper import LuisHelper, Intent\n\n\nclass MainDialog(ComponentDialog):\n    def __init__(\n        self, luis_recognizer: FlightBookingRecognizer, booking_dialog: BookingDialog\n    ):\n        super(MainDialog, self).__init__(MainDialog.__name__)\n\n        self._luis_recognizer = luis_recognizer\n        self._booking_dialog_id = booking_dialog.id\n\n        self.add_dialog(TextPrompt(TextPrompt.__name__))\n        self.add_dialog(booking_dialog)\n        self.add_dialog(\n            WaterfallDialog(\n                \"WFDialog\", [self.intro_step, self.act_step, self.final_step]\n            )\n        )\n\n        self.initial_dialog_id = \"WFDialog\"\n\n    async def intro_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        if not self._luis_recognizer.is_configured:\n            await step_context.context.send_activity(\n                MessageFactory.text(\n                    \"NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and \"\n                    \"'LuisAPIHostName' to the appsettings.json file.\",\n                    input_hint=InputHints.ignoring_input,\n                )\n            )\n\n            return await step_context.next(None)\n        message_text = (\n            str(step_context.options)\n            if step_context.options\n            else \"What can I help you with today?\"\n        )\n        prompt_message = MessageFactory.text(\n            message_text, message_text, InputHints.expecting_input\n        )\n\n        return await step_context.prompt(\n            TextPrompt.__name__, PromptOptions(prompt=prompt_message)\n        )\n\n    async def act_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        if not self._luis_recognizer.is_configured:\n            # LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.\n            return await step_context.begin_dialog(\n                self._booking_dialog_id, BookingDetails()\n            )\n\n        # Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)\n        intent, luis_result = await LuisHelper.execute_luis_query(\n            self._luis_recognizer, step_context.context\n        )\n\n        # top_intent = cognitive_models_helper.top_intent(luis_result['intents'])\n\n        if intent == Intent.BOOK_FLIGHT.value and luis_result:\n            await MainDialog._show_warning_for_unsupported_cities(\n                step_context.context, luis_result\n            )\n\n            # Run the BookingDialog giving it whatever details we have from the LUIS call.\n            return await step_context.begin_dialog(self._booking_dialog_id, luis_result)\n\n        elif intent == Intent.GET_WEATHER.value:\n            get_weather_text = \"TODO: get weather flow here\"\n            get_weather_message = MessageFactory.text(\n                get_weather_text, get_weather_text, InputHints.ignoring_input\n            )\n            await step_context.context.send_activity(get_weather_message)\n\n        else:\n            didnt_understand_text = (\n                \"Sorry, I didn't get that. Please try asking in a different way\"\n            )\n            didnt_understand_message = MessageFactory.text(\n                didnt_understand_text, didnt_understand_text, InputHints.ignoring_input\n            )\n            await step_context.context.send_activity(didnt_understand_message)\n\n        return await step_context.next(None)\n\n    async def final_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        # If the child dialog (\"BookingDialog\") was cancelled or the user failed to confirm,\n        # the Result here will be null.\n        if step_context.result is not None:\n            result = step_context.result\n\n            # Now we have all the booking details call the booking service.\n\n            # If the call to the booking service was successful tell the user.\n            # time_property = Timex(result.travel_date)\n            # travel_date_msg = time_property.to_natural_language(datetime.now())\n            msg_txt = f\"I have you booked to {result.destination} from {result.origin} on {result.travel_date}\"\n            message = MessageFactory.text(msg_txt, msg_txt, InputHints.ignoring_input)\n            await step_context.context.send_activity(message)\n\n        prompt_message = \"What else can I do for you?\"\n        return await step_context.replace_dialog(self.id, prompt_message)\n\n    @staticmethod\n    async def _show_warning_for_unsupported_cities(\n        context: TurnContext, luis_result: BookingDetails\n    ) -> None:\n        if luis_result.unsupported_airports:\n            message_text = (\n                f\"Sorry but the following airports are not supported:\"\n                f\" {', '.join(luis_result.unsupported_airports)}\"\n            )\n            message = MessageFactory.text(\n                message_text, message_text, InputHints.ignoring_input\n            )\n            await context.send_activity(message)\n", "path": "samples/13.core-bot/dialogs/main_dialog.py"}, {"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\nfrom enum import Enum\nfrom typing import Dict\nfrom botbuilder.ai.luis import LuisRecognizer, LuisApplication\nfrom botbuilder.core import IntentScore, TopIntent, TurnContext\n\nfrom booking_details import BookingDetails\n\n\nclass Intent(Enum):\n    BOOK_FLIGHT = \"BookFlight\"\n    CANCEL = \"Cancel\"\n    GET_WEATHER = \"GetWeather\"\n    NONE_INTENT = \"NoneIntent\"\n\n\ndef top_intent(intents: Dict[Intent, dict]) -> TopIntent:\n    max_intent = Intent.NONE_INTENT\n    max_value = 0.0\n\n    for intent, value in intents:\n        intent_score = IntentScore(value)\n        if intent_score.score > max_value:\n            max_intent, max_value = intent, intent_score.score\n\n    return TopIntent(max_intent, max_value)\n\n\nclass LuisHelper:\n    @staticmethod\n    async def execute_luis_query(\n        luis_recognizer: LuisRecognizer, turn_context: TurnContext\n    ) -> (Intent, object):\n        result = None\n        intent = None\n\n        try:\n            recognizer_result = await luis_recognizer.recognize(turn_context)\n\n            intent = (\n                sorted(\n                    recognizer_result.intents,\n                    key=recognizer_result.intents.get,\n                    reverse=True,\n                )[:1][0]\n                if recognizer_result.intents\n                else None\n            )\n\n            if intent == Intent.BOOK_FLIGHT.value:\n                result = BookingDetails()\n\n                # We need to get the result from the LUIS JSON which at every level returns an array.\n                to_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n                    \"To\", []\n                )\n                if len(to_entities) > 0:\n                    if recognizer_result.entities.get(\"To\", [{\"$instance\": {}}])[0][\n                        \"$instance\"\n                    ]:\n                        result.destination = to_entities[0][\"text\"].capitalize()\n                    else:\n                        result.unsupported_airports.append(\n                            to_entities[0][\"text\"].capitalize()\n                        )\n\n                from_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n                    \"From\", []\n                )\n                if len(from_entities) > 0:\n                    if recognizer_result.entities.get(\"From\", [{\"$instance\": {}}])[0][\n                        \"$instance\"\n                    ]:\n                        result.origin = from_entities[0][\"text\"].capitalize()\n                    else:\n                        result.unsupported_airports.append(\n                            from_entities[0][\"text\"].capitalize()\n                        )\n\n                # TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.\n                # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.\n                date_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n                    \"datetime\", []\n                )\n                if len(date_entities) > 0:\n                    result.travel_date = None  # TODO: Set when we get a timex format\n        except Exception as e:\n            print(e)\n\n        return intent, result\n", "path": "samples/13.core-bot/helpers/luis_helper.py"}], "after_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\nfrom botbuilder.core import MessageFactory\nfrom botbuilder.dialogs import WaterfallDialog, DialogTurnResult, WaterfallStepContext\nfrom botbuilder.dialogs.prompts import (\n    DateTimePrompt,\n    PromptValidatorContext,\n    PromptOptions,\n    DateTimeResolution,\n)\nfrom botbuilder.schema import InputHints\nfrom .cancel_and_help_dialog import CancelAndHelpDialog\n\nfrom datatypes_date_time.timex import Timex\n\n\nclass DateResolverDialog(CancelAndHelpDialog):\n    def __init__(self, dialog_id: str = None):\n        super(DateResolverDialog, self).__init__(\n            dialog_id or DateResolverDialog.__name__\n        )\n\n        self.add_dialog(\n            DateTimePrompt(\n                DateTimePrompt.__name__, DateResolverDialog.datetime_prompt_validator\n            )\n        )\n        self.add_dialog(\n            WaterfallDialog(\n                WaterfallDialog.__name__ + \"2\", [self.initial_step, self.final_step]\n            )\n        )\n\n        self.initial_dialog_id = WaterfallDialog.__name__ + \"2\"\n\n    async def initial_step(\n        self, step_context: WaterfallStepContext\n    ) -> DialogTurnResult:\n        timex = step_context.options\n\n        prompt_msg_text = \"On what date would you like to travel?\"\n        prompt_msg = MessageFactory.text(\n            prompt_msg_text, prompt_msg_text, InputHints.expecting_input\n        )\n\n        reprompt_msg_text = \"I'm sorry, for best results, please enter your travel date including the month, day and year.\"\n        reprompt_msg = MessageFactory.text(\n            reprompt_msg_text, reprompt_msg_text, InputHints.expecting_input\n        )\n\n        if timex is None:\n            # We were not given any date at all so prompt the user.\n            return await step_context.prompt(\n                DateTimePrompt.__name__,\n                PromptOptions(prompt=prompt_msg, retry_prompt=reprompt_msg),\n            )\n        # We have a Date we just need to check it is unambiguous.\n        if \"definite\" not in Timex(timex).types:\n            # This is essentially a \"reprompt\" of the data we were given up front.\n            return await step_context.prompt(\n                DateTimePrompt.__name__, PromptOptions(prompt=reprompt_msg)\n            )\n\n        return await step_context.next(DateTimeResolution(timex=timex))\n\n    async def final_step(self, step_context: WaterfallStepContext):\n        timex = step_context.result[0].timex\n        return await step_context.end_dialog(timex)\n\n    @staticmethod\n    async def datetime_prompt_validator(prompt_context: PromptValidatorContext) -> bool:\n        if prompt_context.recognized.succeeded:\n            timex = prompt_context.recognized.value[0].timex.split(\"T\")[0]\n\n            # TODO: Needs TimexProperty\n            return \"definite\" in Timex(timex).types\n\n        return False\n", "path": "samples/13.core-bot/dialogs/date_resolver_dialog.py"}, {"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\nfrom botbuilder.dialogs import (\n    ComponentDialog,\n    WaterfallDialog,\n    WaterfallStepContext,\n    DialogTurnResult,\n)\nfrom botbuilder.dialogs.prompts import TextPrompt, PromptOptions\nfrom botbuilder.core import MessageFactory, TurnContext\nfrom botbuilder.schema import InputHints\n\nfrom .booking_dialog import BookingDialog\nfrom booking_details import BookingDetails\nfrom flight_booking_recognizer import FlightBookingRecognizer\nfrom helpers.luis_helper import LuisHelper, Intent\n\n\nclass MainDialog(ComponentDialog):\n    def __init__(\n        self, luis_recognizer: FlightBookingRecognizer, booking_dialog: BookingDialog\n    ):\n        super(MainDialog, self).__init__(MainDialog.__name__)\n\n        self._luis_recognizer = luis_recognizer\n        self._booking_dialog_id = booking_dialog.id\n\n        self.add_dialog(TextPrompt(TextPrompt.__name__))\n        self.add_dialog(booking_dialog)\n        self.add_dialog(\n            WaterfallDialog(\n                \"WFDialog\", [self.intro_step, self.act_step, self.final_step]\n            )\n        )\n\n        self.initial_dialog_id = \"WFDialog\"\n\n    async def intro_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        if not self._luis_recognizer.is_configured:\n            await step_context.context.send_activity(\n                MessageFactory.text(\n                    \"NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and \"\n                    \"'LuisAPIHostName' to the appsettings.json file.\",\n                    input_hint=InputHints.ignoring_input,\n                )\n            )\n\n            return await step_context.next(None)\n        message_text = (\n            str(step_context.options)\n            if step_context.options\n            else \"What can I help you with today?\"\n        )\n        prompt_message = MessageFactory.text(\n            message_text, message_text, InputHints.expecting_input\n        )\n\n        return await step_context.prompt(\n            TextPrompt.__name__, PromptOptions(prompt=prompt_message)\n        )\n\n    async def act_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        if not self._luis_recognizer.is_configured:\n            # LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance.\n            return await step_context.begin_dialog(\n                self._booking_dialog_id, BookingDetails()\n            )\n\n        # Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)\n        intent, luis_result = await LuisHelper.execute_luis_query(\n            self._luis_recognizer, step_context.context\n        )\n\n        if intent == Intent.BOOK_FLIGHT.value and luis_result:\n            # Show a warning for Origin and Destination if we can't resolve them.\n            await MainDialog._show_warning_for_unsupported_cities(\n                step_context.context, luis_result\n            )\n\n            # Run the BookingDialog giving it whatever details we have from the LUIS call.\n            return await step_context.begin_dialog(self._booking_dialog_id, luis_result)\n\n        elif intent == Intent.GET_WEATHER.value:\n            get_weather_text = \"TODO: get weather flow here\"\n            get_weather_message = MessageFactory.text(\n                get_weather_text, get_weather_text, InputHints.ignoring_input\n            )\n            await step_context.context.send_activity(get_weather_message)\n\n        else:\n            didnt_understand_text = (\n                \"Sorry, I didn't get that. Please try asking in a different way\"\n            )\n            didnt_understand_message = MessageFactory.text(\n                didnt_understand_text, didnt_understand_text, InputHints.ignoring_input\n            )\n            await step_context.context.send_activity(didnt_understand_message)\n\n        return await step_context.next(None)\n\n    async def final_step(self, step_context: WaterfallStepContext) -> DialogTurnResult:\n        # If the child dialog (\"BookingDialog\") was cancelled or the user failed to confirm,\n        # the Result here will be null.\n        if step_context.result is not None:\n            result = step_context.result\n\n            # Now we have all the booking details call the booking service.\n\n            # If the call to the booking service was successful tell the user.\n            # time_property = Timex(result.travel_date)\n            # travel_date_msg = time_property.to_natural_language(datetime.now())\n            msg_txt = f\"I have you booked to {result.destination} from {result.origin} on {result.travel_date}\"\n            message = MessageFactory.text(msg_txt, msg_txt, InputHints.ignoring_input)\n            await step_context.context.send_activity(message)\n\n        prompt_message = \"What else can I do for you?\"\n        return await step_context.replace_dialog(self.id, prompt_message)\n\n    @staticmethod\n    async def _show_warning_for_unsupported_cities(\n        context: TurnContext, luis_result: BookingDetails\n    ) -> None:\n        if luis_result.unsupported_airports:\n            message_text = (\n                f\"Sorry but the following airports are not supported:\"\n                f\" {', '.join(luis_result.unsupported_airports)}\"\n            )\n            message = MessageFactory.text(\n                message_text, message_text, InputHints.ignoring_input\n            )\n            await context.send_activity(message)\n", "path": "samples/13.core-bot/dialogs/main_dialog.py"}, {"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\nfrom enum import Enum\nfrom typing import Dict\nfrom botbuilder.ai.luis import LuisRecognizer\nfrom botbuilder.core import IntentScore, TopIntent, TurnContext\n\nfrom booking_details import BookingDetails\n\n\nclass Intent(Enum):\n    BOOK_FLIGHT = \"BookFlight\"\n    CANCEL = \"Cancel\"\n    GET_WEATHER = \"GetWeather\"\n    NONE_INTENT = \"NoneIntent\"\n\n\ndef top_intent(intents: Dict[Intent, dict]) -> TopIntent:\n    max_intent = Intent.NONE_INTENT\n    max_value = 0.0\n\n    for intent, value in intents:\n        intent_score = IntentScore(value)\n        if intent_score.score > max_value:\n            max_intent, max_value = intent, intent_score.score\n\n    return TopIntent(max_intent, max_value)\n\n\nclass LuisHelper:\n    @staticmethod\n    async def execute_luis_query(\n        luis_recognizer: LuisRecognizer, turn_context: TurnContext\n    ) -> (Intent, object):\n        \"\"\"\n        Returns an object with preformatted LUIS results for the bot's dialogs to consume.\n        \"\"\"\n        result = None\n        intent = None\n\n        try:\n            recognizer_result = await luis_recognizer.recognize(turn_context)\n\n            intent = (\n                sorted(\n                    recognizer_result.intents,\n                    key=recognizer_result.intents.get,\n                    reverse=True,\n                )[:1][0]\n                if recognizer_result.intents\n                else None\n            )\n\n            if intent == Intent.BOOK_FLIGHT.value:\n                result = BookingDetails()\n\n                # We need to get the result from the LUIS JSON which at every level returns an array.\n                to_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n                    \"To\", []\n                )\n                if len(to_entities) > 0:\n                    if recognizer_result.entities.get(\"To\", [{\"$instance\": {}}])[0][\n                        \"$instance\"\n                    ]:\n                        result.destination = to_entities[0][\"text\"].capitalize()\n                    else:\n                        result.unsupported_airports.append(\n                            to_entities[0][\"text\"].capitalize()\n                        )\n\n                from_entities = recognizer_result.entities.get(\"$instance\", {}).get(\n                    \"From\", []\n                )\n                if len(from_entities) > 0:\n                    if recognizer_result.entities.get(\"From\", [{\"$instance\": {}}])[0][\n                        \"$instance\"\n                    ]:\n                        result.origin = from_entities[0][\"text\"].capitalize()\n                    else:\n                        result.unsupported_airports.append(\n                            from_entities[0][\"text\"].capitalize()\n                        )\n\n                # This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.\n                # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.\n                date_entities = recognizer_result.entities.get(\"datetime\", [])\n                if date_entities:\n                    timex = date_entities[0][\"timex\"]\n\n                    if timex:\n                        datetime = timex[0].split(\"T\")[0]\n\n                        result.travel_date = datetime\n\n                else:\n                    result.travel_date = None\n\n        except Exception as e:\n            print(e)\n\n        return intent, result\n", "path": "samples/13.core-bot/helpers/luis_helper.py"}]}