Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save oxanuragofficial/f41c68d263ba0bf4afa4be3c431a16c2 to your computer and use it in GitHub Desktop.

Select an option

Save oxanuragofficial/f41c68d263ba0bf4afa4be3c431a16c2 to your computer and use it in GitHub Desktop.
Beginner-friendly Python guide for social media message automation, setup, usage, troubleshooting, and responsible API-based automation.

Social Message Automation with Python

A beginner-friendly guide to learning messaging automation with Python.

⚠️ Responsible Use

This guide is for educational and legitimate automation purposes. Only automate messages to people who have consented to receive them. Do not use automation for spam, harassment, mass unsolicited messaging, account abuse, or bypassing platform security or anti-bot systems. Always follow the platform's Terms of Service.


πŸ“Œ What Is This?

Social-message automation means using software to perform repetitive messaging tasks instead of manually performing every action.

For example:

Python Program
      ↓
Automation Library
      ↓
Web Browser
      ↓
Your Logged-In Account
      ↓
Message Sent

The program does not hack an account or obtain someone else's credentials.

It operates through an account that you are authorized to use.


πŸ› οΈ Requirements

You generally need:

  • Python 3.8+
  • A computer
  • Internet connection
  • A modern web browser
  • An account on the platform you want to automate
  • Permission to send the messages

Recommended:

  • VS Code
  • Git
  • Python virtual environment

🐍 Python Setup

1. Check Python

Open PowerShell, Command Prompt, Terminal, or another shell.

Run:

python --version

You should get something similar to:

Python 3.12.x

If python is not recognized, install Python from the official Python website and make sure Python is added to your system PATH.


πŸ“ Create a Project

Create a folder:

social-message-automation

Open the folder in VS Code.

You can also use:

mkdir social-message-automation
cd social-message-automation

πŸ”’ Create a Virtual Environment

Run:

python -m venv venv

A folder named venv will be created.

A virtual environment keeps this project's Python packages separate from other projects.


▢️ Activate the Virtual Environment

Windows PowerShell

venv\Scripts\Activate.ps1

Windows Command Prompt

venv\Scripts\activate

macOS / Linux

source venv/bin/activate

After activation, your terminal may show:

(venv)

πŸ“¦ Install a Package

For the WhatsApp Web example used in this guide:

pip install pywhatkit

Check the installation:

pip show pywhatkit

πŸ’¬ WhatsApp Web Example

Create:

main.py

Example:

import pywhatkit as pwk

phone = "+1234567890"
message = "Hello! This is an automated message."

pwk.sendwhatmsg_instantly(phone, message)

Change the phone number

Replace:

phone = "+1234567890"

with the recipient's number, including the international country code.

Example format:

phone = "+91XXXXXXXXXX"

Only use a recipient's number when you have permission to contact them.

Change the message

Modify:

message = "Hello! This is an automated message."

For example:

message = "Hello! I wanted to share an update with you."

▢️ Run the Program

With the virtual environment activated:

python main.py

Depending on the library and browser environment, WhatsApp Web may open in your browser.

If authentication is required, log in using your own account.


πŸ” Important Security Rule

Never put credentials directly into your source code.

Do not write:

password = "my-password"

Do not publish:

  • Passwords
  • API keys
  • Access tokens
  • Session cookies
  • Authentication headers
  • Private phone numbers
  • Private personal information

If credentials are accidentally committed to Git, treat them as exposed and rotate/revoke them.


πŸ’° Does It Cost Money?

For the basic Python + browser example:

Component Typical Cost
Python Free
VS Code Free
Git Free
pywhatkit Free
WhatsApp Web Free
Internet Required

However, costs can apply when using official business APIs, cloud hosting, paid automation platforms, or other third-party services.

Always check the current pricing of the service you choose.


🌐 What About Instagram, Telegram, Discord, and Other Platforms?

Different platforms provide different automation options.

A useful rule is:

Official API available?
        ↓
       YES
        ↓
Prefer the official API

If a platform does not provide an appropriate official API for your intended use, browser automation may be restricted or prohibited.

Do not assume that because browser automation is technically possible, it is allowed.


πŸ“± Common Platforms

Platform Automation Approach
WhatsApp Official APIs / permitted automation tools
Instagram Official Meta APIs where applicable
Facebook Messenger Official Meta APIs where applicable
Telegram Telegram Bot API
Discord Discord bot/API
X Official API where applicable
LinkedIn Official APIs where applicable

Always verify the current platform documentation and Terms of Service before deploying automation.


🚫 What This Project Does NOT Do

This project is not intended to:

  • Hack accounts
  • Steal passwords
  • Bypass authentication
  • Bypass 2FA
  • Bypass CAPTCHA
  • Circumvent anti-bot systems
  • Send spam
  • Send unsolicited bulk messages
  • Collect private credentials
  • Take control of another person's account

πŸ§ͺ Test Safely

Before testing automation:

  1. Use your own account.
  2. Use your own contact/number where possible.
  3. Send a small number of test messages.
  4. Confirm the automation behaves as expected.
  5. Stop if the platform indicates that the activity is restricted.

πŸ› Common Problems

python is not recognized

Try:

python --version

If it fails, install Python and configure PATH.


pip is not recognized

Try:

python -m pip --version

Then install packages with:

python -m pip install pywhatkit

ModuleNotFoundError

Example:

ModuleNotFoundError: No module named 'pywhatkit'

Make sure your virtual environment is activated and run:

python -m pip install pywhatkit

Browser does not open

Check:

  • Internet connection
  • Browser installation
  • Python installation
  • Package installation
  • Browser permissions
  • Whether the platform changed its web interface

πŸ“‚ Recommended Project Structure

social-message-automation/
β”‚
β”œβ”€β”€ venv/
β”‚
β”œβ”€β”€ main.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── .gitignore

Generate dependencies:

pip freeze > requirements.txt

Another user can then install them with:

pip install -r requirements.txt

🧹 .gitignore

Create:

.gitignore

Example:

venv/
__pycache__/
*.pyc
.env
.env.*

This helps prevent local environment files and secrets from being committed.


πŸ”§ Useful Git Commands

Initialize a repository:

git init

Check changes:

git status

Add files:

git add .

Commit:

git commit -m "Add automation example"

Connect a GitHub repository:

git remote add origin YOUR_REPOSITORY_URL

Push:

git push -u origin main

🀝 Contributing

Contributions are welcome.

A typical workflow is:

Fork
  ↓
Clone
  ↓
Create branch
  ↓
Make changes
  ↓
Test
  ↓
Commit
  ↓
Push
  ↓
Pull Request

Create a branch:

git checkout -b improve-documentation

Add changes:

git add .

Commit:

git commit -m "Improve documentation"

Push:

git push -u origin improve-documentation

Then open a Pull Request on GitHub.


⭐ Best Practices

Before publishing automation software:

  • Prefer official APIs.
  • Read the platform's Terms of Service.
  • Obtain recipient consent.
  • Avoid unsolicited messaging.
  • Never publish credentials.
  • Keep dependencies updated.
  • Test with your own account first.
  • Document limitations.
  • Add rate limits where appropriate.
  • Respect platform restrictions.

πŸ“š Learning Path

If you are new to automation, learn in this order:

Python Basics
      ↓
Functions & Modules
      ↓
pip & Virtual Environments
      ↓
HTTP & APIs
      ↓
JSON
      ↓
Authentication
      ↓
Official Platform APIs
      ↓
Automation
      ↓
Testing & Error Handling

Learning official APIs is especially useful because they are generally more stable and predictable than relying on browser-interface automation.


πŸ“œ License

Check the original project's license before redistributing or modifying its code.

If you are the project maintainer, consider adding an explicit open-source license such as MIT or Apache-2.0.


⭐ Summary

Python can make repetitive tasks easier, but responsible automation matters.

Use automation to:

  • Save time
  • Learn programming
  • Build legitimate tools
  • Automate your own workflows
  • Work with official APIs

Do not use it to:

  • Spam people
  • Abuse accounts
  • Bypass security
  • Circumvent platform restrictions
  • Access accounts without authorization

Automate responsibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment