#!/bin/bash set -e API_BASE="https://imamjavad.newhorizonco.uk/api" LIVE_BASE="https://live.newhorizonco.uk" DEFAULT_COURSE_SLUG="test-1-ghorbani" DEFAULT_AUTH_TOKEN="e5ec00c7660302c3225276eaf7be99459c9a7012" AUTH_TOKEN="$DEFAULT_AUTH_TOKEN" COURSE_SLUG="$DEFAULT_COURSE_SLUG" print_usage() { echo "Usage: $0 [-t ] [-s ] [-h]" echo "" echo "Options:" echo " -t User authentication token (default: test-1-ghorbani user token)" echo " -s Course slug (default: test-1-ghorbani)" echo " -h Show this help message" echo "" echo "Example:" echo " $0" echo " $0 -s my-course" echo " $0 -t custom-token -s custom-course" } while getopts "t:s:h" opt; do case $opt in t) AUTH_TOKEN="$OPTARG" ;; s) COURSE_SLUG="$OPTARG" ;; h) print_usage; exit 0 ;; *) print_usage; exit 1 ;; esac done echo "✓ Using authentication token" echo "" echo "Step 1: Creating live session room..." ROOM_RESPONSE=$(curl -s -X POST "$API_BASE/courses/$COURSE_SLUG/online/room/create/" \ -H "Content-Type: application/json" \ -H "Authorization: Token $AUTH_TOKEN" \ -d '{}') CREATED_ROOM_ID=$(echo "$ROOM_RESPONSE" | grep -o '"room_id":"[^"]*' | cut -d'"' -f4 | head -1) if [ -z "$CREATED_ROOM_ID" ]; then echo "Error: Failed to create room" echo "Response: $ROOM_RESPONSE" exit 1 fi echo "✓ Room created: $CREATED_ROOM_ID" echo "" echo "Step 2: Getting join token..." TOKEN_RESPONSE=$(curl -s -X POST "$API_BASE/courses/online/room/token/" \ -H "Content-Type: application/json" \ -H "Authorization: Token $AUTH_TOKEN" \ -d "{\"course_slug\": \"$COURSE_SLUG\"}") JOIN_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"token":"[^"]*' | cut -d'"' -f4) if [ -z "$JOIN_TOKEN" ]; then echo "Error: Failed to get join token" echo "Response: $TOKEN_RESPONSE" exit 1 fi echo "✓ Join token generated" echo "" FULL_URL="$LIVE_BASE/?access_token=$JOIN_TOKEN" echo "==========================================" echo "Room created successfully!" echo "==========================================" echo "" echo "Full Room Link:" echo "$FULL_URL" echo "" echo "Room Details:" echo " Room ID: $CREATED_ROOM_ID" echo " Course: $COURSE_SLUG" echo "=========================================="