Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better data input management for MS botframwork #8190

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8190.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Botframework channel can now handle both text and value inputs coming from Microsoft bots.
19 changes: 18 additions & 1 deletion rasa/core/channels/botframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ async def health(request: Request) -> HTTPResponse:

@botframework_webhook.route("/webhook", methods=["POST"])
async def webhook(request: Request) -> HTTPResponse:
""" Webhook receiving requests from MS Botframework.

Comment on lines +217 to +218
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups, still some whitespaces left here:

Suggested change
""" Webhook receiving requests from MS Botframework.
"""Webhook receiving requests from MS Botframework.

The request contains data about end-user messages or actions.
The content of the Activity object exchanged in this request
is detailed in MS:
https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#activity-object

"""
postdata = request.json
metadata = self.get_metadata(request)

Expand All @@ -231,8 +239,17 @@ async def webhook(request: Request) -> HTTPResponse:
postdata["serviceUrl"],
)

text = ""
if postdata.get("text"):
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
text = postdata.get("text")
elif postdata.get("value"):
raw_value = postdata.get("value")
if "value" in raw_value:
raw_value = raw_value["value"]
text = json.dumps(raw_value)

user_msg = UserMessage(
text=postdata.get("text", ""),
text=text,
output_channel=out_channel,
sender_id=postdata["from"]["id"],
input_channel=self.name(),
Expand Down