Thanks to visit codestin.com
Credit goes to github.com

Skip to content

albert1bs/10bisAuto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

10bis Automation System

An automated system for managing 10bis credit loading and token refresh operations. Choose from three deployment options: GitHub Actions (cloud-based, no server required), Linux Server (traditional cron-based), or Docker (containerized testing).

Features

  • Automatic Token Refresh: Refreshes authentication tokens every 10 minutes
  • Scheduled Credit Loading: Loads 10bis credit daily at 10 AM (excluding weekends)
  • Microsoft Teams Notifications: Real-time notifications for success/failure with amount and timestamp
  • Robust Error Handling: Comprehensive logging and retry mechanisms
  • Secure Token Management: Automatic token updates and encrypted storage
  • Weekend Detection: Automatically skips credit loading on Friday and Saturday
  • Multiple Deployment Options: GitHub Actions, Linux Server, or Docker
  • Zero Maintenance: GitHub Actions option requires no server maintenance

Deployment

πŸš€ GitHub Actions (Cloud-based)

This system is designed for GitHub Actions deployment

βœ… Advantages:

  • No server required - runs in GitHub's cloud
  • Automatic token updates stored securely in GitHub secrets
  • Built-in logging and monitoring
  • Free for most usage (2,000 minutes/month)
  • Zero maintenance and security updates
  • Microsoft Teams notifications

❌ Requirements:

  • GitHub repository (free)
  • GitHub Personal Access Token

πŸ“– Setup Guide: GITHUB-ACTIONS-SETUP.md

Quick Start

GitHub Actions Setup

# 1. Push your code to GitHub
git init
git add .
git commit -m "Initial commit"
git push origin main

# 2. Set up GitHub secrets (see GITHUB-ACTIONS-SETUP.md)
# 3. Update tokens when needed:
npm run update-github-secrets

# 4. The automation starts running automatically!

Installation

1. Clone the Repository

git clone <repository-url> 10bis-automation
cd 10bis-automation

2. Install Dependencies

npm install

3. Set up GitHub Repository Secrets

Follow the GITHUB-ACTIONS-SETUP.md guide to configure:

  • ACCESS_TOKEN
  • REFRESH_TOKEN
  • AMOUNT
  • MONEYCARD_ID
  • TEAMS_WEBHOOK_URL (optional)
  • PERSONAL_ACCESS_TOKEN

4. Update Tokens When Needed

# Update GitHub repository secrets with fresh tokens
npm run update-github-secrets

# Test Teams notifications
npm run test-teams-connection

πŸ“– Teams Setup Guide: TEAMS-SETUP.md

Cron Job Setup

1. Find Node.js Path

which node
# Example output: /usr/bin/node

2. Get Project Path

pwd
# Example output: /home/user/10bis-automation

3. Edit Crontab

crontab -e

4. Add Cron Jobs

Copy the following lines to your crontab, replacing the paths with your actual paths:

# Token Refresh - Every 10 minutes
*/10 * * * * /usr/bin/node /home/user/10bis-automation/refresh-token.js >> /home/user/10bis-automation/logs/cron.log 2>&1

# Credit Loading - Daily at 10 AM (excluding Friday and Saturday)
0 10 * * 0,1,2,3,4 /usr/bin/node /home/user/10bis-automation/load-credit.js >> /home/user/10bis-automation/logs/cron.log 2>&1

5. Verify Cron Jobs

crontab -l

File Structure

10bis-automation/
β”œβ”€β”€ package.json                        # Node.js project configuration
β”œβ”€β”€ config.json                         # Authentication tokens and settings (local dev)
β”œβ”€β”€ README.md                           # Main documentation
β”œβ”€β”€ GITHUB-ACTIONS-SETUP.md             # GitHub Actions deployment guide
β”œβ”€β”€ DEPLOYMENT.md                       # Linux server deployment guide
β”œβ”€β”€ DOCKER-TESTING.md                   # Docker testing guide
β”œβ”€β”€ TEAMS-SETUP.md                      # Microsoft Teams notifications setup guide
β”œβ”€β”€ TOKEN-TROUBLESHOOTING.md            # Token refresh troubleshooting guide
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── 10bis-automation.yml        # GitHub Actions workflow
β”œβ”€β”€ github-actions-utils.js             # GitHub Actions compatible utilities
β”œβ”€β”€ github-refresh-token.js             # Token refresh for GitHub Actions
β”œβ”€β”€ github-load-credit.js               # Credit loading for GitHub Actions
β”œβ”€β”€ utils.js                            # Utility functions (server deployment)
β”œβ”€β”€ refresh-token.js                    # Token refresh script (server deployment)
β”œβ”€β”€ load-credit.js                      # Credit loading script (server deployment)
β”œβ”€β”€ teams-notifier.js                   # Teams notification utility (server deployment)
β”œβ”€β”€ github-teams-notifier.js            # Teams notification utility (GitHub Actions)
β”œβ”€β”€ test.js                             # Comprehensive test suite
β”œβ”€β”€ test-teams-notifications.js         # Teams notification testing script
β”œβ”€β”€ debug-token-refresh.js              # Token refresh debugging utility
β”œβ”€β”€ update-tokens.js                    # Token update utility for local config
β”œβ”€β”€ update-github-secrets.js            # GitHub repository secrets update utility
β”œβ”€β”€ deploy.sh                           # Automated deployment script for Linux
β”œβ”€β”€ crontab-setup.txt                   # Cron job configuration examples
β”œβ”€β”€ Dockerfile                          # Docker container configuration
β”œβ”€β”€ docker-compose.yml                  # Docker Compose configuration
β”œβ”€β”€ .dockerignore                       # Docker build optimization
└── logs/                               # Log files directory (created automatically)
    β”œβ”€β”€ refresh.log                     # Token refresh logs
    β”œβ”€β”€ credit.log                      # Credit loading logs
    β”œβ”€β”€ error.log                       # Error logs
    β”œβ”€β”€ test.log                        # Test execution logs
    β”œβ”€β”€ teams-test.log                  # Teams notification test logs
    β”œβ”€β”€ debug-token-refresh.log         # Token refresh debug logs
    β”œβ”€β”€ token-update.log                # Token update logs
    β”œβ”€β”€ github-secrets-update.log       # GitHub secrets update logs
    └── cron.log                        # Cron job execution logs

Monitoring and Logs

Log Files

  • refresh.log: Token refresh operations
  • credit.log: Credit loading operations
  • error.log: All error messages
  • cron.log: Cron job execution output

View Recent Logs

# View last 50 lines of refresh logs
tail -n 50 logs/refresh.log

# View last 50 lines of credit logs
tail -n 50 logs/credit.log

# View error logs
tail -n 50 logs/error.log

# Monitor logs in real-time
tail -f logs/refresh.log

Check Cron Job Status

# Check if cron service is running
systemctl status cron

# View cron logs (Ubuntu/Debian)
grep CRON /var/log/syslog

# View cron logs (CentOS/RHEL)
grep CRON /var/log/messages

Troubleshooting

Common Issues

  1. Scripts not running via cron

    • Check file permissions: ls -la *.js
    • Verify Node.js path: which node
    • Check cron service: systemctl status cron
  2. Authentication errors (HTTP 401)

    • Quick fix for local: Update tokens manually: npm run update-tokens
    • Quick fix for GitHub Actions: Update repository secrets: npm run update-github-secrets
    • Check current token status: npm run token-status
    • Run detailed debug: npm run debug-tokens
    • See TOKEN-TROUBLESHOOTING.md for detailed solutions
    • Verify tokens in config.json are current
    • Check if manual token refresh works: npm run refresh-token
  3. Missing dependencies

    • Run npm install in the project directory
    • Check Node.js version: node --version
  4. Permission denied errors

    • Set proper permissions: chmod +x *.js
    • Secure config file: chmod 600 config.json

Manual Testing

# Test token refresh manually
node refresh-token.js

# Test credit loading configuration
node load-credit.js --test

# Test credit loading (respects weekend check)
node load-credit.js

# Test Teams notifications
npm run test-teams-connection

# Test Teams notifications with full messages
npm run test-teams

# View Teams setup instructions
npm run teams-setup

# Debug token refresh issues
npm run debug-tokens

# Check current token status
npm run token-status

# Update tokens manually for local development
npm run update-tokens

# Update GitHub repository secrets for GitHub Actions
npm run update-github-secrets

# Get help for GitHub Personal Access Token setup
npm run github-token-help

Debug Mode

Add debug logging by modifying the log level in utils.js or check the detailed logs in the logs/ directory.

Security Considerations

  • Keep config.json secure with restricted permissions (600)
  • Regularly rotate authentication tokens
  • Monitor log files for suspicious activity
  • Consider using environment variables for sensitive data in production

API Endpoints

The system interacts with these 10bis API endpoints:

  • Token Refresh: POST https://api.10bis.co.il/api/v1/Authentication/RefreshToken
  • Credit Loading: PATCH https://api.10bis.co.il/api/v1/Payments/LoadTenbisCredit

Schedule Details

  • Token Refresh: Every 10 minutes, 24/7
  • Credit Loading: Daily at 10:00 AM Israel time, Monday through Thursday and Sunday
  • Weekend Skip: Automatically skips Friday and Saturday

Support

For issues or questions:

  1. Check the log files in the logs/ directory
  2. Verify your configuration in config.json
  3. Test scripts manually before troubleshooting cron issues
  4. Ensure all dependencies are installed with npm install

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published