diff --git a/index.js b/index.js new file mode 100644 index 0000000000..26de85b526 --- /dev/null +++ b/index.js @@ -0,0 +1,39 @@ +require('dotenv').config() +const app = require('express')() +const { Telegraf } = require('telegraf') +const { getPrayerTimes } = require('./utils') + +const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN || ''); + + +bot.start((ctx) => ctx.reply('Assalamualaikum, Welcome to Prayer Time Bot')); + +bot.help((ctx) => ctx.reply('Send me a sticker')); + +bot.hears('hi', (ctx) => ctx.reply('Hey there')); + +bot.command('hariini', async (ctx) => { + const waktu = await getPrayerTimes("today", "JHR03") + let str = '' + waktu.prayerTime.map((time) => { + Object.entries(time).forEach(([key, value]) => { + str = str.concat(`${key}: ${value}\n`) + }) + }) + ctx.reply(str) +}); + +bot.launch(); + +process.once('SIGINT', () => bot.stop('SIGINT')); +process.once('SIGTERM', () => bot.stop('SIGTERM')); + +app.get('/prayerTime', async (req, res) => { + const { period, zone } = req.query + const prayerTime = await getPrayerTimes(period, zone) + res.json(prayerTime) +}) + +app.listen(process.env.PORT || 3000, () => { + console.log('--------server is ruuning on port', 3000) +}) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000000..66de7aa53c --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "axios": "^1.3.6", + "dotenv": "^16.0.3", + "express": "^4.18.2", + "nodemon": "^2.0.22", + "telegraf": "^4.12.2" + }, + "scripts": { + "dev": "nodemon index" + } +} \ No newline at end of file diff --git a/utils/index.js b/utils/index.js new file mode 100644 index 0000000000..e59b288eaf --- /dev/null +++ b/utils/index.js @@ -0,0 +1,88 @@ +const axios = require('axios'); +const https = require('https') + +const Period = { + Today: 'today', + Week: 'week', + Month: 'month', + Year: 'year', + Duration: 'duration' +} + +const getZones = () => { + return new Promise((resolve, reject) => { + const url = "https://www.e-solat.gov.my/index.php?siteId=24&pageId=24"; + https.get(url, (res) => { + let result = ''; + res.on('data', (chunk) => { + result += chunk; + }); + res.on('end', () => { + const pattern = /