def get_service_dicts_for_bots(bot_dicts: List[Dict[(str, Any)]], realm: Realm) -> Dict[(int, List[Dict[(str, Any)]])]:
    bot_profile_ids = [bot_dict['id'] for bot_dict in bot_dicts]
    bot_services_by_uid: Dict[(int, List[Service])] = defaultdict(list)
    for service in Service.objects.filter(user_profile_id__in=bot_profile_ids):
        bot_services_by_uid[service.user_profile_id].append(service)
    embedded_bot_ids = [bot_dict['id'] for bot_dict in bot_dicts if (bot_dict['bot_type'] == UserProfile.EMBEDDED_BOT)]
    embedded_bot_configs = get_bot_configs(embedded_bot_ids)
    service_dicts_by_uid: Dict[(int, List[Dict[(str, Any)]])] = {}
    for bot_dict in bot_dicts:
        bot_profile_id = bot_dict['id']
        bot_type = bot_dict['bot_type']
        services = bot_services_by_uid[bot_profile_id]
        service_dicts: List[Dict[(str, Any)]] = []
        if (bot_type == UserProfile.OUTGOING_WEBHOOK_BOT):
            service_dicts = [{'base_url': service.base_url, 'interface': service.interface, 'token': service.token} for service in services]
        elif (bot_type == UserProfile.EMBEDDED_BOT):
            if (bot_profile_id in embedded_bot_configs.keys()):
                bot_config = embedded_bot_configs[bot_profile_id]
                service_dicts = [{'config_data': bot_config, 'service_name': services[0].name}]
        service_dicts_by_uid[bot_profile_id] = service_dicts
    return service_dicts_by_uid
def get_service_dicts_for_bots(bot_dicts: List[Dict[(str, Any)]], realm: Realm) -> Dict[(int, List[Dict[(str, Any)]])]:
    bot_profile_ids = [bot_dict['id'] for bot_dict in bot_dicts]
    bot_services_by_uid: Dict[(int, List[Service])] = defaultdict(list)
    for service in Service.objects.filter(user_profile_id__in=bot_profile_ids):
        bot_services_by_uid[service.user_profile_id].append(service)
    embedded_bot_ids = [bot_dict['id'] for bot_dict in bot_dicts if (bot_dict['bot_type'] == UserProfile.EMBEDDED_BOT)]
    embedded_bot_configs = get_bot_configs(embedded_bot_ids)
    service_dicts_by_uid: Dict[(int, List[Dict[(str, Any)]])] = {}
    for bot_dict in bot_dicts:
        bot_profile_id = bot_dict['id']
        bot_type = bot_dict['bot_type']
        services = bot_services_by_uid[bot_profile_id]
        service_dicts: List[Dict[(str, Any)]] = []
        if (bot_type == UserProfile.OUTGOING_WEBHOOK_BOT):
            service_dicts = [{'base_url': service.base_url, 'interface': service.interface, 'token': service.token} for service in services]
        elif (bot_type == UserProfile.EMBEDDED_BOT):
            if (bot_profile_id in embedded_bot_configs.keys()):
                bot_config = embedded_bot_configs[bot_profile_id]
                service_dicts = [{'config_data': bot_config, 'service_name': services[0].name}]
        service_dicts_by_uid[bot_profile_id] = service_dicts
    return service_dicts_by_uid