Skip to content

Commit

Permalink
add prompt validator
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfcabral committed Mar 20, 2024
1 parent 8a751fc commit 153f2b9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion botgen/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from typing import Union

from botbuilder.core import MessageFactory
from botbuilder.dialogs import ActivityPrompt
from botbuilder.dialogs import Dialog
from botbuilder.dialogs import DialogContext
from botbuilder.dialogs import DialogReason
from botbuilder.dialogs import DialogTurnResult
from botbuilder.dialogs import DialogTurnStatus
from botbuilder.dialogs import PromptValidatorContext
from botbuilder.schema import ActionTypes
from botbuilder.schema import Activity
from botbuilder.schema import ActivityTypes
Expand Down Expand Up @@ -76,6 +78,15 @@ def __init__(self, dialog_id: str, controller):
self.script: Dict[str, List] = {}
self._controller = controller

activity_prompt = ActivityPrompt(self._prompt, self._prompt_validator)
self._controller.dialog_set.add(activity_prompt)

async def _prompt_validator(self, prompt: PromptValidatorContext):
"""
Runs when a new activity is added
"""
return prompt.recognized.succeeded == True

def add_message(self, message: BotMessageTemplate | str, thread_name: str = None):
"""
Adds a message template to a specific thread.
Expand Down Expand Up @@ -196,7 +207,7 @@ def add_question(
option["type"] = "string"

self.script[thread_name].append(message)
self.script[thread_name].append({"action": "next"})
self.script[thread_name].append(BotMessageTemplate(action="next"))
return self

def ask(
Expand Down

0 comments on commit 153f2b9

Please sign in to comment.