Skip to content

pmutua/sms-parser-api

Repository files navigation

SMS Backup Restore parser API


This API parses the XML file generated by the SMS Backup & Restore Android app, which is saved to Google Drive. The file contains structured records of SMS and MMS messages, including details like sender, receiver, timestamps, and message content. This data can then be accessed and processed for further automation or analysis.

python manage.py import_contacts contacts.csv

Usage


This tool assumes the default file naming convention of the SMS Backup & Restore Android app, e.g.,

sms-20180101000000.xml

Use Service Account (For Server-Side Access)

A service account allows you to access Google Drive programmatically without user interaction. This is useful for backend scripts or automation

Step 1: Create a Service Account

  1. Go to Google Cloud Console.
  2. Select your project or create a new one.
  3. Navigate to APIs & Services > Credentials.
  4. Click Create Credentials > Service Account.
  5. Give it a name and description, then click Create.
  6. Under "Grant this service account access to project", assign the Editor or Owner role (for full access) or Drive API Admin.
  7. Click Create & Continue until done.

Step 2: Generate and Download the JSON Key

  1. Go to APIs & Services > Credentials.
  2. Click on your service account.
  3. Under Keys, click Add Key > JSON.
  4. Download the JSON file securely.
  5. Rename the downloaded file to service_account.json and add to credentials/service_account.json

Step 3: Enable Google Drive API

  1. Go to APIs & Services > Library.
  2. Search for Google Drive API and enable it.

Step 4: Share Google Drive Folder with Service Account

  1. Create a folder on Google Drive.
  2. Share the folder with the Service Account email (you can find this email in the service account details).
  3. Ensure the service account has the necessary permissions (Viewer, Editor, or higher).

Step 5: Move SMS Backup File to Google Drive Folder

  1. Use SMS Backup & Restore Android app to backup theh file will be saved on GDrive.
  2. Open Google Drive and navigate to the folder you shared with the service account.
  3. Drag and drop the SMS backup file into the shared folder.
  4. The file will now be stored in the Google Drive folder and accessible by the service account.

Endpoint

API Documentation: Get Latest SMS Backup

Endpoint: GET /api/get_latest_sms

Retrieves the latest SMS backup data for a specified provider.

Authentication

This endpoint requires API key authentication.

Header:

X-API-Key: your-api-key

Request Parameters

Parameter Type Required Description
provider string Yes The name of the cloud service provider

Response

Success Response (200 OK)

{
  "sms_messages": [
    {
      "id": "123456",
      "sender": "+1234567890",
      "recipient": "+0987654321",
      "timestamp": "2025-04-20T14:30:00Z",
      "message": "Example message content"
    },
    ...
  ]
}

Error Responses

400 Bad Request

{
  "error": "Provider parameter is required"
}

400 Bad Request

{
  "error": "Invalid provider: {provider}"
}

400 Bad Request

{
  "error": "No SMS backup found."
}

401 Unauthorized

{
  "detail": "API key required"
}

401 Unauthorized

{
  "detail": "Invalid API key"
}

500 Internal Server Error

{
  "error": "An unexpected error occurred. Please try again later."
}

Example Requests

Using cURL

curl -X GET "https://your-domain.com/api/get_latest_sms?provider=google_drive" \
  -H "X-API-Key: your-api-key"

Using Python Requests

import requests

url = "https://your-domain.com/api/get_latest_sms"
headers = {
    "X-API-Key": "your-api-key"
}
params = {
    "provider": "google_drive"
}

response = requests.get(url, headers=headers, params=params)
print(response.json())

Using Postman

  1. Set request method to GET
  2. Enter URL: https://your-domain.com/api/get_latest_sms?provider=google_drive
  3. Under the Headers tab, add:
    • Key: X-API-Key
    • Value: your-api-key
  4. Click Send

Notes

  • API keys should be kept secure and not shared publicly
  • All requests should be made over HTTPS to ensure the API key is transmitted securely
  • The response format may vary depending on the provider and available SMS data

SMS Backup to Google Drive and XML Processing

---
title: Illustration
---
flowchart LR
    A[Android App] -->|"1. Backup"| B[(Google Drive)]
    
    subgraph "Django API"
        direction TB
        C[Drive Client] -->|"2. Retrieve"| B
        C -->|"3. Parse"| D[XML → JSON]
        D --> E[Django Backend]
    end
    
    E -.->|"4. Future"| F[Make Automation]
    F -.->|"Workflows"| G[Use Cases]
    
    classDef mobile fill:#A4C639,color:white
    classDef storage fill:#4285F4,color:white
    classDef process fill:#34A853,color:white
    classDef convert fill:#FBBC05,color:black
    classDef backend fill:#EA4335,color:white
    classDef future fill:#9C27B0,color:white,stroke-dasharray:5 5
    
    class A mobile
    class B storage
    class C process
    class D convert
    class E backend
    class F,G future
Loading

UseCase

You can create automations with the parsed data using Make (formerly Integromat).

flowchart TD
    AndroidApp["SMS Backup & Restore\n(Android App)"]
    
    subgraph "Storage" 
        GDrive["Google Drive\n(XML Storage)"]
        XMLFile["Personal SMS XML Files"]
    end
    
    subgraph "API Processing"
        Parser["XML Parser API"]
        Extract["Extract & Parse Messages"]
    end
    
    subgraph "Integration Platform"
        Make["Make.com"]
    end
    
    subgraph "Use Case Processing"
        UC1["Message Archiving & Retrieval"]
        UC2["Communication Insights"]
    end
    
    subgraph "Automation Ideas"
        D1["Digital Memory Palace\n- 3D visualization\n- Spatial-temporal mapping of conversations"]
        D2["Relationship Genome Project\n- Communication DNA mapping\n- Predictive relationship insights"]
        D3["Conversational Time Machine\n- Life timeline generation\n- Past self-reflection"]
        D4["Behavioral Economics Insights\n- Decision pattern analysis\n- Commitment tracking"]
        D5["Cross-Platform Identity Unification\n- Aggregated messaging\n- Digital communication profile"]
        D6["AI-Powered Emotion Tracker\n- Real-time sentiment analysis\n- Emotional evolution over time"]
        D7["Historical Message Replay\n- Message-based video reenactments\n- Virtual reality conversation immersion"]
        D8["Personalized Conversational Assistant\n- AI-driven conversation summary\n- Memory-based context suggestions"]
        D9["Predictive Conversation Mapping\n- Predicting conversation flow\n- Context-aware suggestions"]
        D10["Collective Intelligence Network\n- Collaborative message analysis\n- Shared learning from group conversations"]
        D11["Memory Augmentation System\n- Neural augmentation of conversation memory\n- Enhanced recall of past interactions"]
        D12["Life Planning Assistant\n- Context-aware life goal recommendations\n- Personalized life strategy advice"]
        D13["Self-Reflection Journal\n- AI-driven conversation-based journaling\n- Personalized life analysis based on messages"]
        D14["Stress Reduction Tracker\n- Real-time monitoring of stress-inducing messages\n- Relaxation tips based on tone and context"]
        D15["Confidence Builder\n- Sentiment and tone analysis to enhance personal confidence\n- Growth tracking over time"]
        D16["Digital Therapy Companion\n- Conversation-based mental health support\n- AI-driven emotional check-ins"]
        D17["Time Management Assistant\n- Prioritize conversations that impact productivity\n- Automate task reminders based on messages"]
        D18["Virtual Coach for Personal Development\n- Habit tracking and improvement suggestions\n- Personalized motivation based on past conversations"]
        D19["Financial Conversation Advisor\n- Budgeting and financial advice based on message patterns\n- Detect spending habits and recommend savings"]
        D20["Personalized Relationship Growth\n- Analyze conversation dynamics\n- Suggest improvements for personal relationships"]
        D21["Personal Well-Being Dashboard\n- Holistic health monitoring based on message tone and content\n- Life balance tracking"]
        D22["Health Behavior Tracker\n- Track health-related conversations and correlate them to personal well-being trends"]
        D23["Sleep & Rest Insights\n- Analyze sleep-related conversations and offer rest optimization tips"]
        D24["Mindfulness Enhancer\n- Track mindfulness-related conversations\n- Provide daily mindfulness exercises"]
        D25["Social Support Network\n- Identify key support people in your conversations\n- Strengthen social ties with regular check-ins"]
        D26["Creative Idea Generator\n- AI-based idea suggestions from past conversations\n- Creative brainstorming tool based on message data"]
        D27["Virtual Memory Box\n- Store and categorize significant life moments\n- Revisit and reflect on key life events over time"]
        D28["Voice of Self Tracker\n- Analyze your own evolving communication style\n- Track personal growth in expressing thoughts and feelings"]
        D29["Personalized Productivity Insights\n- Actionable insights on improving productivity based on message analysis"]
        D30["Behavioral Habit Formation\n- Track and suggest improvements to personal habits based on conversation data"]
        D31["Behavioral Pattern Recognizer\n- Identify anomalous communication patterns\n- Trigger alerts"]
        D32["Conversation Impact Analyzer\n- Assess influence of messages on behavior\n- Provide actionable recommendations"]
        D33["Conversation Sentiment Forecasting\n- Predict upcoming sentiment trends\n- Alert on potential mood shifts"]
        D34["Interactive Chat History Map\n- Visualize conversation threads over time\n- Interactive exploration"]
        D35["Smart Notification Filter\n- Prioritize messages by importance\n- Reduce notification overload"]
        D36["Voice-Activated Message Summarizer\n- Convert voice messages to summaries\n- Enhance accessibility"]
        D37["Conversation Recap Bot\n- Summarize daily conversation highlights\n- Automated daily briefs"]
        D38["Topic Clustering Assistant\n- Group messages by common themes\n- Improve content organization"]
        D39["Message Urgency Classifier\n- Identify time-sensitive messages\n- Prioritize urgent communications"]
        D40["Emotion Dynamics Analyzer\n- Track shifts in emotional tone\n- Visualize mood trajectories"]
        D41["Data-Driven Relationship Advisor\n- Leverage data for relationship tips\n- Personalized advice engine"]
        D42["Social Interaction Heatmap\n- Visualize peak messaging times\n- Understand interaction density"]
        D43["Conversation Quality Evaluator\n- Rate conversation effectiveness\n- Provide improvement suggestions"]
        D44["Conflict Detection System\n- Identify emerging conflicts\n- Propose resolution strategies"]
        D45["Personal Communication Trends\n- Analyze style changes over time\n- Offer communication coaching"]
        D46["Predictive Conversation Engagement\n- Forecast engagement levels\n- Optimize interaction timing"]
        D47["Behavioral Change Detector\n- Detect shifts in communication habits\n- Early alert system"]
        D48["Personal Reminder Engine\n- Extract actionable reminders\n- Automate follow-up tasks"]
        D49["Sentiment-Triggered Actions\n- Initiate actions based on mood\n- Context-aware automation"]
        D50["Conversational Mood Board\n- Create visual mood collages\n- Reflect on emotional history"]
        D51["Message Habit Analyzer\n- Identify recurring communication patterns\n- Recommend habit improvements"]
        D52["Customized Response Suggestion\n- Generate tailored reply suggestions\n- AI-powered conversational aid"]
        D53["Longitudinal Communication Study\n- Analyze trends over extended periods\n- Research-grade insights"]
        D54["Cross-Platform Message Sync\n- Ensure consistent messaging across devices\n- Seamless integration"]
        D55["Virtual Archive Explorer\n- Intuitive navigation of past messages\n- Enhanced retrieval experience"]
        D56["Memory Lane Navigator\n- Context-rich exploration of old conversations\n- Nostalgia mapping"]
        D57["Conversation Impact Predictor\n- Forecast outcomes of ongoing chats\n- Data-driven predictions"]
        D58["Self-Reflection Prompter\n- Offer introspective prompts\n- Encourage personal growth"]
        D59["Interaction Frequency Analyzer\n- Measure communication regularity\n- Trend visualization"]
        D60["Personal Data Visualizer\n- Graph and chart messaging data\n- Insights at a glance"]
        D61["Message Context Extractor\n- Pull key themes from chats\n- Enhance understanding"]
        D62["Automated Communication Coach\n- Provide tips for improved messaging\n- AI-guided suggestions"]
        D63["Narrative Generation Tool\n- Create narrative summaries\n- Story-based conversation recaps"]
        D64["Digital Legacy Curator\n- Organize messages for posterity\n- Create a digital memoir"]
        D65["Behavior Prediction Module\n- Anticipate future messaging behavior\n- Proactive recommendations"]
        D66["Interactive Communication Simulator\n- Model conversation scenarios\n- Practice interpersonal skills"]
        D67["Message Relevance Scorer\n- Rate messages based on importance\n- Filter out noise"]
        D68["Insightful Conversation Analyzer\n- Deep dive into dialogue nuances\n- Uncover hidden patterns"]
        D69["Interactive Dialogue Enhancer\n- Tools to elevate live conversations\n- Real-time suggestions"]
        D70["AI-Based Messaging Coach\n- Personalized coaching for communication\n- Enhance message effectiveness"]
        D71["Message Anomaly Detector\n- Spot outlier messages quickly\n- Alert on unusual patterns"]
        D72["Conversational Ecosystem Analyzer\n- Holistic view of social interactions\n- Cross-network insights"]
    end
    
    AndroidApp --> GDrive
    GDrive --> XMLFile
    XMLFile --> Parser
    Parser --> Extract
    Extract --> Make
    
    Make --> UC1
    Make --> UC2
    Make --> D1
    Make --> D2
    Make --> D3
    Make --> D4
    Make --> D5
    Make --> D6
    Make --> D7
    Make --> D8
    Make --> D9
    Make --> D10
    Make --> D11
    Make --> D12
    Make --> D13
    Make --> D14
    Make --> D15
    Make --> D16
    Make --> D17
    Make --> D18
    Make --> D19
    Make --> D20
    Make --> D21
    Make --> D22
    Make --> D23
    Make --> D24
    Make --> D25
    Make --> D26
    Make --> D27
    Make --> D28
    Make --> D29
    Make --> D30
    Make --> D31
    Make --> D32
    Make --> D33
    Make --> D34
    Make --> D35
    Make --> D36
    Make --> D37
    Make --> D38
    Make --> D39
    Make --> D40
    Make --> D41
    Make --> D42
    Make --> D43
    Make --> D44
    Make --> D45
    Make --> D46
    Make --> D47
    Make --> D48
    Make --> D49
    Make --> D50
    Make --> D51
    Make --> D52
    Make --> D53
    Make --> D54
    Make --> D55
    Make --> D56
    Make --> D57
    Make --> D58
    Make --> D59
    Make --> D60
    Make --> D61
    Make --> D62
    Make --> D63
    Make --> D64
    Make --> D65
    Make --> D66
    Make --> D67
    Make --> D68
    Make --> D69
    Make --> D70
    Make --> D71
    Make --> D72
    
    classDef app fill:#FF5733,stroke:#900C3F,stroke-width:2px,color:white
    classDef storage fill:#3498DB,stroke:#1A5276,stroke-width:2px,color:white
    classDef api fill:#F39C12,stroke:#9A7D0A,stroke-width:2px,color:black
    classDef integration fill:#9B59B6,stroke:#6C3483,stroke-width:2px,color:white
    classDef usecase fill:#16A085,stroke:#0E6655,stroke-width:2px,color:white
    classDef disruptive fill:#E74C3C,stroke:#943126,stroke-width:2px,color:white
    
    class AndroidApp app
    class GDrive,XMLFile storage
    class Parser,Extract api
    class Make integration
    class UC1,UC2 usecase
    class D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13,D14,D15,D16,D17,D18,D19,D20,D21,D22,D23,D24,D25,D26,D27,D28,D29,D30,D31,D32,D33,D34,D35,D36,D37,D38,D39,D40,D41,D42,D43,D44,D45,D46,D47,D48,D49,D50,D51,D52,D53,D54,D55,D56,D57,D58,D59,D60,D61,D62,D63,D64,D65,D66,D67,D68,D69,D70,D71,D72 disruptive

Loading