|
| 1 | +# |
| 2 | +# Copyright (c) 2024, Daily |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD 2-Clause License |
| 5 | +# |
| 6 | + |
| 7 | +import argparse |
| 8 | +import os |
| 9 | + |
| 10 | +import aiohttp |
| 11 | + |
| 12 | +from pipecat.transports.services.helpers.daily_rest import DailyRESTHelper |
| 13 | + |
| 14 | + |
| 15 | +async def configure(aiohttp_session: aiohttp.ClientSession): |
| 16 | + """Configure the Daily room and Daily REST helper.""" |
| 17 | + parser = argparse.ArgumentParser(description="Daily AI SDK Bot Sample") |
| 18 | + parser.add_argument( |
| 19 | + "-u", "--url", type=str, required=False, help="URL of the Daily room to join" |
| 20 | + ) |
| 21 | + parser.add_argument( |
| 22 | + "-k", |
| 23 | + "--apikey", |
| 24 | + type=str, |
| 25 | + required=False, |
| 26 | + help="Daily API Key (needed to create an owner token for the room)", |
| 27 | + ) |
| 28 | + |
| 29 | + args, unknown = parser.parse_known_args() |
| 30 | + |
| 31 | + url = args.url or os.getenv("DAILY_SAMPLE_ROOM_URL") |
| 32 | + key = args.apikey or os.getenv("DAILY_API_KEY") |
| 33 | + |
| 34 | + if not url: |
| 35 | + raise Exception( |
| 36 | + "No Daily room specified. use the -u/--url option from the command line, or set DAILY_SAMPLE_ROOM_URL in your environment to specify a Daily room URL." |
| 37 | + ) |
| 38 | + |
| 39 | + if not key: |
| 40 | + raise Exception( |
| 41 | + "No Daily API key specified. use the -k/--apikey option from the command line, or set DAILY_API_KEY in your environment to specify a Daily API key, available from https://dashboard.daily.co/developers." |
| 42 | + ) |
| 43 | + |
| 44 | + daily_rest_helper = DailyRESTHelper( |
| 45 | + daily_api_key=key, |
| 46 | + daily_api_url=os.getenv("DAILY_API_URL", "https://api.daily.co/v1"), |
| 47 | + aiohttp_session=aiohttp_session, |
| 48 | + ) |
| 49 | + |
| 50 | + # Create a meeting token for the given room with an expiration 1 hour in |
| 51 | + # the future. |
| 52 | + expiry_time: float = 60 * 60 |
| 53 | + |
| 54 | + token = await daily_rest_helper.get_token(url, expiry_time) |
| 55 | + |
| 56 | + return (url, token) |
0 commit comments