{"id":28389216,"url":"https://github.com/es7/intelligent-whatsapp-bots","last_synced_at":"2026-07-03T22:33:03.835Z","repository":{"id":293972426,"uuid":"985652654","full_name":"ES7/Intelligent-WhatsApp-Bots","owner":"ES7","description":"Implementation of WhatsApp Bot for YouTube Video Summarization","archived":false,"fork":false,"pushed_at":"2025-05-18T09:40:59.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T02:15:56.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ES7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-18T08:31:20.000Z","updated_at":"2025-05-18T09:41:03.000Z","dependencies_parsed_at":"2025-05-18T10:30:50.496Z","dependency_job_id":null,"html_url":"https://github.com/ES7/Intelligent-WhatsApp-Bots","commit_stats":null,"previous_names":["es7/whatsapp-bot-for-youtube-video-summarization","es7/intelligent-whatsapp-bots"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ES7/Intelligent-WhatsApp-Bots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ES7%2FIntelligent-WhatsApp-Bots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ES7%2FIntelligent-WhatsApp-Bots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ES7%2FIntelligent-WhatsApp-Bots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ES7%2FIntelligent-WhatsApp-Bots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ES7","download_url":"https://codeload.github.com/ES7/Intelligent-WhatsApp-Bots/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ES7%2FIntelligent-WhatsApp-Bots/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35104113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-31T00:37:54.616Z","updated_at":"2026-07-03T22:33:03.819Z","avatar_url":"https://github.com/ES7.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intelligent-WhatsApp-Bots\n\n## Code Explaination for `YT_Videos_Summarization.py`:\nImport all the necessary files, then initialze the Flask App.\n```python\napp = Flask(__name__)\n```\nThis line initializes a new Flask web application. `__name__` tells Flask where to look for resources like templates and static files.\n\n### Configure the Gemini API\n```python\ngenai.configure(api_key='YOUR_API_KEY_HERE')\nmodel = genai.GenerativeModel('gemini-1.5-flash-002')\n```\nSet your API key so that your application can authenticate and use Google’s Gemini model. Load the **Gemini 1.5 Flash model** (an efficient, fast model) which you'll use later to summarize the text.\n\n### Function to Extract Video URL\n```python\ndef extract_video_id(url):\n    match = re.search(r\"(?:v=|\\/)([0-9A-Za-z_-]{11}).*\", url)\n    return match.group(1) if match else None\n```\n- This function extracts the video ID from a YouTube link. YouTube videos have a unique 11-character ID.\n- Whether the URL is in the format: **`https://www.youtube.com/watch?v=AbCd1234EfGh`**  or  **`https://youtu.be/AbCd1234EfGh`**.\n- The regular expression searches for the 11-character ID after `v=` or a `/`.\n- To fetch a transcript via the `YouTubeTranscriptApi`, you must supply just the **video ID**, not the whole URL.\n\n### Function for Summarization\n```python\ndef summarize_text(text):\n    prompt = \"Summarize this YouTube video transcript in simple points:\\n\\n\" + text\n    response = model.generate_content(prompt)\n    return response.text\n```\n- This function sends the transcript text to Google Gemini with a prompt asking it to summarize the video in simple bullet points.\n- It makes a call to Gemini and returns the summarized result. `response.text` gives us the clean text of the summary.\n\n### Function to Save the File as `.txt`\n```python\ndef save_summary_to_file(summary, video_id):\n    filename = f\"{video_id}_summary.txt\"\n    filepath = os.path.join(\"summaries\", filename)\n    os.makedirs(\"summaries\", exist_ok=True)\n    with open(filepath, \"w\", encoding=\"utf-8\") as f:\n        f.write(summary)\n    return filepath\n```\n- This function creates a `.txt` file with the summary so that the user can download it from a link. `video_id_summary.txt` helps keep filenames unique per video. The summaries folder is automatically created if it doesn't already exist using `os.makedirs()`. The summary content is then written to the file using UTF-8 encoding.\n- Twilio doesn't support long messages well. So instead of pasting a long summary in WhatsApp, you give the user a link to download it.\n\n### Flask Routes \u0026 WhatsApp Bot Logic\n```python\n@app.route(\"/\", methods=['GET', 'POST'])\ndef whatsapp_bot():\n    if request.method == 'GET':\n        return \"WhatsApp bot is running.\"\n```\n- This defines the main route (/) of your Flask app.\n- If the server is accessed via browser (GET request), it simply returns a plain message: \"WhatsApp bot is running.\"\n- This is useful to check if your app is online.\n\n### WhatsApp Message Handling (POST request from Twilio)\n```python\nincoming_msg = request.values.get('Body', '').strip()\nresp = MessagingResponse()\nmsg = resp.message()\n```\n- `incoming_msg` gets the actual text message sent by the user on WhatsApp.\n- `MessagingResponse()` is part of Twilio’s library. It builds a response back to the user.\n- `msg = resp.message()` is where you prepare your reply.\n\n### Check for YouTube Link\n```python\nif \"youtube.com\" in incoming_msg or \"youtu.be\" in incoming_msg:\n```\nChecks if the message includes a YouTube link.\n\n### Extract \u0026 Validate Video ID\n```python\nvideo_id = extract_video_id(incoming_msg)\nif not video_id:\n    msg.body(\"Invalid YouTube link. Please try again.\")\n    return str(resp)\n```\n- Uses your earlier `extract_video_id()` function.\n- If a valid video ID isn’t found, it sends an error message.\n\n### Fetch Transcript, Summarize \u0026 Send Back\n```python\ntranscript = YouTubeTranscriptApi.get_transcript(video_id)\nfull_text = \" \".join([t['text'] for t in transcript])\nsummary = summarize_text(full_text)\n```\n- Fetches the full transcript using the video ID.\n- Joins all transcript lines into one string.\n- Sends it to Gemini to get the summary.\n\n### Save and Share the Summary\n```python\nfilepath = save_summary_to_file(summary, video_id)\nfile_url = request.host_url + f\"summaries/{video_id}_summary.txt\"\nmsg.body(f\"Summary ready! Download here:\\n{file_url}\")\n```\n- Saves the summary using your earlier `save_summary_to_file()` function.\n- Constructs a download link using your Flask app's current URL + file path.\n- Sends the user a link to download the `.txt` file.\n\n### Catch Transcript Errors\n```python\nexcept Exception as e:\n    msg.body(\"Failed to fetch transcript. It might be disabled or unavailable.\")\n```\n- The transcript is not available (some videos disable captions),\n- Or there’s a network or API issue.\n\n### Handle Invalid Inputs\n```python\nelse:\n    msg.body(\"Please send a valid YouTube video link.\")\n```\nIf the message doesn’t contain a YouTube link, the user is informed to send a valid one.\n\n### Return the Response\n```python\nreturn str(resp)\n```\nThis sends the prepared response message back to Twilio → which sends it to WhatsApp.\n\n### File Serving Route\n```python\n@app.route('/summaries/\u003cpath:filename\u003e')\ndef serve_summary_file(filename):\n    return send_from_directory(os.path.join(os.getcwd(), 'summaries'), filename)\n```\n- This route lets you serve the saved `.txt` file when the user clicks the link.\n- It looks for the file in the `summaries/` directory and serves it for download.\n\n### App Start\n```python\nif __name__ == '__main__':\n    app.run(debug=True)\n```\n- Starts the Flask development server when you run the script.\n- `debug=True` allows you to see errors more clearly during development.\n\n\nFor futher detail read my medium article: **[WhatsApp Bot for YouTube Video Summarization](https://medium.com/@sayedebad.777/whatsapp-bot-for-youtube-video-summarization-0509dca41906)**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fes7%2Fintelligent-whatsapp-bots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fes7%2Fintelligent-whatsapp-bots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fes7%2Fintelligent-whatsapp-bots/lists"}