Skip to content

Commit

Permalink
Added Courier Tracker Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberboysumanjay committed Oct 2, 2021
1 parent 8704285 commit c0c7e34
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
- **watch** - Find out where to watch a Movie/Show
- **shorten** - Get Short URL
- **ocr** - Extract Text from Image
- **courier** - Fetches latest status of Courier/Shipments from multiple providers

[More modules]("https://github.com/TheWhatsBot/WhatsBot/wiki/Commands")

### Deploy :

[![Deploy with Heroku](https://www.herokucdn.com/deploy/button.svg "Deploy with Heroku")](https://heroku.com/deploy?template=https://github.com/TheWhatsBot/WhatsBot "Deploy with Heroku")<br>
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template?template=https%3A%2F%2Fgithub.com%2FTheWhatsBot%2FWhatsBot&plugins=mongodb&envs=SESSION%2CPMPERMIT_ENABLED%2CDEFAULT_TR_LANG%2CENABLE_DELETE_ALERT%2CYT_DATA_API_KEY%2COCR_SPACE_API_KEY%2CINFOSPACE_API_KEY&optionalEnvs=YT_DATA_API_KEY%2COCR_SPACE_API_KEY%2CINFOSPACE_API_KEY&SESSIONDesc=Puppeteer+Session.+Ge+it+by+running+genToken.js&PMPERMIT_ENABLEDDesc=Enable+Pmpermit+write+true+or+false+only&DEFAULT_TR_LANGDesc=Default+Translation+Language&ENABLE_DELETE_ALERTDesc=If+true+and+if+someone+delete+message+in+PM%2C+Bot+will+send+the+deleted+message+in+that+chat+%28Exclude+Media%29&YT_DATA_API_KEYDesc=Youtube+DATA+API+key+grab+it+from+cloud.google.com&OCR_SPACE_API_KEYDesc=Get+it+from+https%3A%2F%2Focr.space%2FOCRAPI&INFOSPACE_API_KEYDesc=Get+it+from+https%3A%2F%2Finfospace.club&PMPERMIT_ENABLEDDefault=true&DEFAULT_TR_LANGDefault=en&referralCode=tuhin)

### Commands :

_Send <code>!help</code> in Anywhere. Or read this [Command's Wiki](https://github.com/TheWhatsBot/WhatsBot/wiki/Commands "Command's Wiki")_
Expand Down
65 changes: 65 additions & 0 deletions commands/courier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//jshint esversion:8
// Coded by Sumanjay (https://github.com/cyberboysumanjay)
const {
MessageMedia
} = require('whatsapp-web.js');
const axios = require('axios');

async function getTrackingDetails(trackingService, trackingNumber) {
let mainconfig = {
method: 'get',
url: `https://sjcourierapi.deta.dev/${trackingService}/${trackingNumber}` //Feel free to use this API for your own use.
};
console.log(mainconfig.url);
let statusString = "Unable to get information for your shipment. Please check the tracking id or try again later!"
return axios(mainconfig)
.then(async function (response) {
let data = response.data;
if (trackingService == "gati") {
let status = data.result
if (status == "successful") {
let dktInfo = data.dktInfo[0];
console.log(dktInfo);
statusString = `Your shipment having docket number ${dktInfo.dktno} booked from ${dktInfo.bookingStation} to ${dktInfo.deliveryStation} by ${dktInfo.consigneeName} is having current status of ${dktInfo.docketStatus}.\nIt is scheduled to be delivered to ${dktInfo.ReceiversName} on or before ${dktInfo.assuredDlyDate}.`
}
} else if (trackingService == "ekart") {
try {
merchant = data.merchantName
if (merchant != null) {
let merchantName = merchant == "FKMP" ? "Flipkart" : merchant;
let reachedNearestHub = data.reachedNearestHub ? "has reached nearest hub" : "is yet to reach nearest hub"
statusString = `Your shipment having tracking number ${trackingNumber} booked from ${data.sourceCity} to ${data.destinationCity} by ${merchantName} ${reachedNearestHub}.\nYour shipment is expected to be delivered to ${data.receiverName} on or before ${data.expectedDeliveryDate}.`
}
} catch (error) {
console.log(error)
}
}
let out = ({
status: statusString
});
return out;
})
.catch(function (error) {
console.log(error);
return "error";
});
}
const execute = async (client, msg, args) => {
msg.delete(true);
let data = await getTrackingDetails(args[0], args[1]);
if (data == "error") {
await client.sendMessage(msg.to, `🙇‍♂️ *Error*\n\n` + "```Something unexpected happened while fetching the courier details.```");
} else {
await client.sendMessage(msg.to, `🙇‍♂️ *Courier/Shipment Details*\n\n` + "```" + data.status + "```");
}
};

module.exports = {
name: 'Courier',
description: 'Get courier details from multiple providers. Currently supports: Gati Express and Ekart',
command: '!courier',
commandType: 'plugin',
isDependent: false,
help: `*courier*\n\nGet information about your couriers and shipments. \n\n*!courier [courier-name] [tracking-id]*\n`,
execute
};

0 comments on commit c0c7e34

Please sign in to comment.