eshaa
eshaa

Reputation: 587

web response statement not displaying on bot screen

I am implementing a chatbot for teams using teams toolkit, azure open AI and bot framework. In the following code, if particular message is received from user, the code should display a particular message back to user emulator and teams screen and not process Azure open AI gpt-4o. the below code doesn't execute azure open AI gpt-4o model when "hey" is received but it doesn't display on the screen either. whats wrong with the code?

@routes.post("/api/messages")
async def on_messages(req: web.Request) -> web.Response:
    print("on_messages ************* ")
    if req.path == "/api/messages" and req.method == "POST":
        print("Processing POST request to /api/messages")
        data = await req.json()
        user_input = data.get('text', "").lower()

        print("User Input:", user_input)
        if "hey" in user_input:
            # Create an activity response to send back to the emulator
            response_activity = Activity(
                type=ActivityTypes.message,
                text="not found"
            )
            print("response_activity", response_activity)
            return web.json_response(response_activity.serialize(), status=HTTPStatus.OK)
        
        # Create a new payload with the modified data
        new_payload = json.dumps(data).encode('utf-8')
        req._read_bytes = new_payload

    res = await bot_app.process(req)
        
    if res is not None:
        # Return the response from the bot app processing
        return res
    return web.Response(status=HTTPStatus.OK)

Upvotes: 0

Views: 21

Answers (0)

Related Questions