This script uses the Aftership API to track packages and sends notifications to a Telegram chat.
- Tracks packages using the Aftership API.
- Sends notifications to Telegram.
- Handles different couriers.
- Archives delivered packages.
Before running the script, make sure you have the following dependencies installed:
curl: A command-line tool for transferring data with URLs.jq: A lightweight and flexible command-line JSON processor.
You can install them using your system's package manager. For example, on Debian-based systems:
sudo apt-get update
sudo apt-get install curl jq-
Create
config.sh:Create a
config.shfile in the same directory as the script and add the following content:#!/bin/bash # Aftership API API="YOUR_AFTERSHIP_API_KEY" # Telegram API APITELEGRAM="YOUR_TELEGRAM_BOT_API_KEY" # Telegram Chat ID CHATID="YOUR_TELEGRAM_CHAT_ID"
Replace the placeholder values with your actual API keys and chat ID.
-
Add Tracking Numbers:
Open
colis.confand add your tracking numbers in the following format:slug;colis_number;commentslug: The courier's slug (e.g.,colissimo,ups).colis_number: The tracking number of the package.comment: A brief description of the package.
Example:
colissimo;9L12345678901;My first package
To run the script, execute the following command:
./aftership.shYou can also use the display argument to print the tracking information to the console:
./aftership.sh displayTo automate the tracking process, you can set up a cron job to run the script at regular intervals. For example, to run the script every 30 minutes, add the following line to your crontab:
*/30 * * * * /path/to/aftership.sh
The script reads the tracking numbers from colis.conf, retrieves the tracking information from the Aftership API, and compares the latest checkpoint with the previous one. If there is a new update, it sends a notification to the specified Telegram chat.
When a package is marked as "Delivered," the script comments out the corresponding line in colis.conf and archives the tracking data.