async def parse_request(req):
        """
        Parses and validates request
        :param req:
        :return:
        """

        async def validate_activity(activity: Activity):
            if not isinstance(activity.type, str):
                raise TypeError('BotFrameworkAdapter.parse_request(): invalid or missing activity type.')
            return True

        if not isinstance(req, Activity):
            # If the req is a raw HTTP Request, try to deserialize it into an Activity and return the Activity.
            if hasattr(req, 'body'):
                try:
                    activity = Activity().deserialize(req.body)
                    is_valid_activity = await validate_activity(activity)
                    if is_valid_activity:
                        return activity
                except Exception as e:
                    raise e
            elif 'body' in req:
                try:
                    activity = Activity().deserialize(req['body'])
                    is_valid_activity = await validate_activity(activity)
                    if is_valid_activity:
                        return activity
                except Exception as e:
                    raise e
            else:
                raise TypeError('BotFrameworkAdapter.parse_request(): received invalid request')
        else:
            # The `req` has already been deserialized to an Activity, so verify the Activity.type and return it.
            is_valid_activity = await validate_activity(req)
            if is_valid_activity:
                return req
async def parse_request(req):
        """
        Parses and validates request
        :param req:
        :return:
        """

        async def validate_activity(activity: Activity):
            if not isinstance(activity.type, str):
                raise TypeError('BotFrameworkAdapter.parse_request(): invalid or missing activity type.')
            return True

        if not isinstance(req, Activity):
            # If the req is a raw HTTP Request, try to deserialize it into an Activity and return the Activity.
            if hasattr(req, 'body'):
                try:
                    activity = Activity().deserialize(req.body)
                    is_valid_activity = await validate_activity(activity)
                    if is_valid_activity:
                        return activity
                except Exception as e:
                    raise e
            elif 'body' in req:
                try:
                    activity = Activity().deserialize(req['body'])
                    is_valid_activity = await validate_activity(activity)
                    if is_valid_activity:
                        return activity
                except Exception as e:
                    raise e
            else:
                raise TypeError('BotFrameworkAdapter.parse_request(): received invalid request')
        else:
            # The `req` has already been deserialized to an Activity, so verify the Activity.type and return it.
            is_valid_activity = await validate_activity(req)
            if is_valid_activity:
                return req
async def parse_request ( req ) : async def validate_activity ( activity : Activity ) : if not isinstance ( activity . type , str ) : raise TypeError ( 'BotFrameworkAdapter.parse_request(): invalid or missing activity type.' ) return True if not isinstance ( req , Activity ) : # If the req is a raw HTTP Request, try to deserialize it into an Activity and return the Activity. if hasattr ( req , 'body' ) : try : activity = Activity ( ) . deserialize ( req . body ) is_valid_activity = await validate_activity ( activity ) if is_valid_activity : return activity except Exception as e : raise e elif 'body' in req : try : activity = Activity ( ) . deserialize ( req [ 'body' ] ) is_valid_activity = await validate_activity ( activity ) if is_valid_activity : return activity except Exception as e : raise e else : raise TypeError ( 'BotFrameworkAdapter.parse_request(): received invalid request' ) else : # The `req` has already been deserialized to an Activity, so verify the Activity.type and return it. is_valid_activity = await validate_activity ( req ) if is_valid_activity : return req
Parses and validates request
        :param req:
        :return:
Parses and validates request : param req : : return :