-
Notifications
You must be signed in to change notification settings - Fork 0
[init] first implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| <a id="readme-top"></a> | ||
|
|
||
| <!-- PROJECT SHIELDS --> | ||
| [![License][license-shield]][license-url] | ||
| [![Forks][forks-shield]][forks-url] | ||
| [![Stargazers][stars-shield]][stars-url] | ||
| [![Issues][issues-shield]][issues-url] | ||
|
|
||
| <!-- PROJECT LOGO --> | ||
| <div align="center"> | ||
| <h1>Example Google Sheets Integration</h1> | ||
|
|
||
| <p> | ||
| Google Apps Script integration to automatically log incoming SMS messages to Google Sheets | ||
| <br /> | ||
| <br /> | ||
| <a href="#-about-the-project"><strong>About The Project</strong></a> | ||
| · | ||
| <a href="#-getting-started"><strong>Getting Started</strong></a> | ||
| · | ||
| <a href="#-usage"><strong>Usage</strong></a> | ||
| · | ||
| <a href="#-contributing"><strong>Contributing</strong></a> | ||
| </p> | ||
| </div> | ||
|
|
||
| <!-- TABLE OF CONTENTS --> | ||
| - [🌐 About The Project](#-about-the-project) | ||
| - [🛠️ Built With](#️-built-with) | ||
| - [🚀 Getting Started](#-getting-started) | ||
| - [📋 Prerequisites](#-prerequisites) | ||
| - [⚙️ Installation](#️-installation) | ||
| - [💻 Usage](#-usage) | ||
| - [📨 Webhook Payload Structure](#-webhook-payload-structure) | ||
| - [🔧 Troubleshooting](#-troubleshooting) | ||
| - [🤝 Contributing](#-contributing) | ||
| - [📜 License](#-license) | ||
|
|
||
|
|
||
| <!-- ABOUT THE PROJECT --> | ||
| ## 🌐 About The Project | ||
|
|
||
| This project provides a Google Apps Script integration for SMSGate that automatically logs incoming SMS messages to a Google Sheet. When SMS messages are received through the app, a webhook is sent to this script which parses the message data and appends it to your Google Sheet with the following columns: | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - **Timestamp**: When the message was received | ||
| - **From**: The phone number that sent the message | ||
| - **Message**: The SMS message content | ||
| - **DeviceID**: The device ID | ||
| - **MessageID**: The unique message ID | ||
|
|
||
| ### 🛠️ Built With | ||
|
|
||
| - [Google Apps Script](https://developers.google.com/apps-script) | ||
| - [Google Sheets](https://sheets.google.com) | ||
|
|
||
| <p align="right"><a href="#readme-top">back to top</a></p> | ||
|
|
||
| <!-- GETTING STARTED --> | ||
| ## 🚀 Getting Started | ||
|
|
||
| Follow these instructions to set up the SMSGate Google Sheets integration. | ||
|
|
||
| ### 📋 Prerequisites | ||
|
|
||
| - A Google account | ||
| - Access to Google Sheets | ||
| - An SMSGate app on your phone | ||
|
|
||
| ### ⚙️ Installation | ||
|
|
||
| 1. **Create a new Google Sheet** | ||
| - Go to [sheets.google.com](https://sheets.google.com) | ||
| - Create a new blank spreadsheet | ||
| - Name the spreadsheet "SMS Messages" or your preferred name | ||
| - Rename the first sheet to "Messages" (this is required by the script) | ||
| - Add the following headers to row 1: | ||
|
|
||
| ``` | ||
| Timestamp | From | Message | DeviceID | MessageID | ||
| ``` | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 2. **Open the Apps Script Editor** | ||
| - In your Google Sheet, click on `Extensions` > `Apps Script` | ||
| - This will open the Apps Script editor in a new tab | ||
|
|
||
| 3. **Deploy the Script** | ||
| - Remove any existing code in the editor | ||
| - Copy the code from [`code.gs`](code.gs) and paste it into the Apps Script editor | ||
| - Click the "Save project" icon (floppy disk) | ||
|
|
||
| 4. **Deploy the Web App** | ||
| - Click on "Deploy" > "New deployment" | ||
| - Click on the "Select type" dropdown and choose "Web app" | ||
| - Under "Execute as", select "Me (your account)" | ||
| - Under "Who has access", select "Anyone" | ||
| - Click "Deploy" | ||
| - Authorize the script when prompted (you may need to select your Google account) | ||
| - Copy the "Web app URL", e.g. | ||
|
|
||
| ``` | ||
| https://script.google.com/macros/s/AKfycbx.../exec | ||
| ``` | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 5. **Configure sms-gate.app Webhook** | ||
| - [Register a new webhook](https://docs.sms-gate.app/features/webhooks/#step-2-register-your-webhook-endpoint) with the URL from step 4 | ||
|
|
||
| 6. **Test the Setup** | ||
| - Send a test SMS message to your phone | ||
| - Check your Google Sheet - the message should appear automatically | ||
| - Verify all columns are populated correctly | ||
|
|
||
| <p align="right"><a href="#readme-top">back to top</a></p> | ||
|
|
||
| <!-- USAGE EXAMPLES --> | ||
| ## 💻 Usage | ||
|
|
||
| ### 📨 Webhook Payload Structure | ||
|
|
||
| The script expects webhook payloads from SMSGate in the following format: | ||
|
|
||
| ```json | ||
| { | ||
| "deviceId": "your-device-id", | ||
| "payload": { | ||
| "messageId": "unique-message-id", | ||
| "message": "Hello, this is a test message", | ||
| "phoneNumber": "+1234567890", | ||
| "receivedAt": "2024-12-01T10:30:00Z" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### 🔧 Troubleshooting | ||
|
|
||
| - **Sheet not found**: Ensure your sheet is named exactly "Messages" | ||
| - **Data not appearing**: Check that your webhook URL is correct and accessible | ||
| - **Authorization errors**: Re-deploy the web app with proper permissions | ||
| - **Column mismatch**: Verify your headers match exactly: "Timestamp", "From", "Message", "DeviceID", "MessageID" | ||
|
|
||
| <p align="right"><a href="#readme-top">back to top</a></p> | ||
|
|
||
| <!-- CONTRIBUTING --> | ||
| ## 🤝 Contributing | ||
|
|
||
| Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. | ||
|
|
||
| If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". | ||
| Don't forget to give the project a star! Thanks again! | ||
|
|
||
| 1. Fork the Project | ||
| 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) | ||
| 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) | ||
| 4. Push to the Branch (`git push origin feature/AmazingFeature`) | ||
| 5. Open a Pull Request | ||
|
|
||
| <p align="right"><a href="#readme-top">back to top</a></p> | ||
|
|
||
| <!-- LICENSE --> | ||
| ## 📜 License | ||
|
|
||
| Distributed under the Apache License 2.0. See `LICENSE` for more information. | ||
|
|
||
| <p align="right"><a href="#readme-top">back to top</a></p> | ||
|
|
||
| <!-- MARKDOWN LINKS & IMAGES --> | ||
| <!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --> | ||
| [license-shield]: https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=for-the-badge | ||
| [license-url]: https://opensource.org/licenses/Apache-2.0 | ||
| [forks-shield]: https://img.shields.io/github/forks/android-sms-gateway/example-webhooks-google-sheets.svg?style=for-the-badge | ||
| [forks-url]: https://github.com/android-sms-gateway/example-webhooks-google-sheets/network/members | ||
| [stars-shield]: https://img.shields.io/github/stars/android-sms-gateway/example-webhooks-google-sheets.svg?style=for-the-badge | ||
| [stars-url]: https://github.com/android-sms-gateway/example-webhooks-google-sheets/stargazers | ||
| [issues-shield]: https://img.shields.io/github/issues/android-sms-gateway/example-webhooks-google-sheets.svg?style=for-the-badge | ||
| [issues-url]: https://github.com/android-sms-gateway/example-webhooks-google-sheets/issues | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * Google Apps Script to receive incoming SMS messages from sms-gate.app webhooks | ||
| * and append them to a Google Sheet. | ||
| */ | ||
| function doPost(e) { | ||
| try { | ||
| // Get the active sheet by name | ||
| const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Messages'); | ||
| if (!sheet) throw new Error("Sheet 'Messages' not found"); | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Parse incoming JSON body | ||
| const body = JSON.parse(e.postData.contents); | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Extract fields from the webhook payload according to sms-gate.app docs | ||
| const { | ||
| deviceId, | ||
| payload, | ||
| } = body; | ||
|
|
||
| if (!payload) { | ||
| throw new Error("Missing required field: payload"); | ||
| } | ||
|
|
||
| const { | ||
| messageId, | ||
| message, | ||
| phoneNumber, | ||
| receivedAt, | ||
| } = payload; | ||
|
|
||
| if (!message || !phoneNumber) { | ||
| throw new Error("Missing required fields: message or phoneNumber"); | ||
| } | ||
|
|
||
| // Append to sheet | ||
| sheet.appendRow([ | ||
| new Date(receivedAt || Date.now()), | ||
| phoneNumber || '', | ||
| message || '', | ||
| deviceId || '', | ||
| messageId || '' | ||
| ]); | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Return success response | ||
| return ContentService | ||
| .createTextOutput(JSON.stringify({ status: 'ok' })) | ||
| .setMimeType(ContentService.MimeType.JSON); | ||
|
|
||
| } catch (err) { | ||
| // Handle errors gracefully | ||
| Logger.log("Webhook error: " + err.message); | ||
| return ContentService | ||
| .createTextOutput(JSON.stringify({ status: 'error', message: err.message })) | ||
| .setMimeType(ContentService.MimeType.JSON); | ||
| } | ||
capcom6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.