Skip to content

Commit 9731b07

Browse files
committed
Added license
1 parent 94fd2e7 commit 9731b07

5 files changed

Lines changed: 100 additions & 64 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Matan Mashraki
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <img src=public/logo.png width="32"> NotifyBot
1+
# <img src="https://raw.githubusercontent.com/planecore/NotifyBot/main/public/logo.png" width="32"> NotifyBot
22
Send yourself push notifications with Telegram.
33

44
## Usage
@@ -11,24 +11,28 @@ Use the website or the API:
1111
- **schedule (optional):** Provide an ISO date string to send the message at
1212

1313
## Installation
14+
[Docker Hub](https://hub.docker.com/r/planecore/notifybot)
15+
1416
Create a new Telegram Bot with [@BotFather](https://t.me/botfather) and create a token.
1517

1618
Fill the BOT_TOKEN, leave CHAT_ID empty and start the container.
1719

1820
```
19-
notifybot:
20-
image: planecore/notifybot
21-
ports:
22-
- "3000:3000"
23-
environment:
24-
- BOT_TOKEN=
25-
- CHAT_ID=
26-
volumes:
27-
- ./db:/usr/src/app/db
28-
restart: unless-stopped
21+
version: "3"
22+
services:
23+
notifybot:
24+
image: planecore/notifybot
25+
ports:
26+
- "3000:3000"
27+
environment:
28+
- BOT_TOKEN=
29+
- CHAT_ID=
30+
volumes:
31+
- ./db:/usr/src/app/db
32+
restart: unless-stopped
2933
```
3034

31-
After your container loaded, send the bot this command: `/get_chat_id`
35+
After your container loaded, send this command to the bot: /get_chat_id
3236

3337
Copy the reply the bot sent and place it in CHAT_ID.
3438

@@ -40,4 +44,3 @@ Restart the container the NotifyBot is ready to go!
4044
- Database: [LokiJS](https://github.com/techfort/LokiJS)
4145
- Telegram Bot: [node-telegram-bot-api](https://github.com/yagop/node-telegram-bot-api)
4246
- Logo: [Geist Icons](https://github.com/geist-org/react-icons)
43-

src/pages/api/send.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { NextApiRequest, NextApiResponse } from "next"
2-
import TelegramBot from "node-telegram-bot-api"
32
import { sendMessage } from "../../data/bot"
43
import { getDbInstance, save } from "../../data/db"
54

src/pages/index.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import Message from "../models/Message"
1414
import { FormEvent, useState } from "react"
1515
import { useRouter } from "next/router"
16-
import TelegramBot from "node-telegram-bot-api"
1716
import { MuiPickersUtilsProvider, DateTimePicker } from "@material-ui/pickers"
1817
import DayJSUtils from "@date-io/dayjs"
1918
import { ParsedUrlQuery } from "querystring"
@@ -73,17 +72,31 @@ const HomePage: NextPage<HomePageProps> = ({ messages }) => {
7372
>
7473
<Tabs.Item label="Send Now" value="false" />
7574
<Tabs.Item label="Send Later" value="true">
76-
<MuiPickersUtilsProvider utils={DayJSUtils}>
77-
<DateTimePicker
78-
value={scheduleDate}
79-
inputVariant="outlined"
80-
style={{ height: 30 }}
81-
onChange={(date) => setScheduleDate(date.toDate())}
82-
ampm={false}
83-
autoOk
84-
disablePast
85-
/>
86-
</MuiPickersUtilsProvider>
75+
<div style={{ height: 40 }}>
76+
<div style={{ position: "absolute" }}>
77+
<Button type="secondary" ghost>
78+
{scheduleDate.toLocaleString("en-US", {
79+
month: "short",
80+
day: "numeric",
81+
hour: "numeric",
82+
minute: "2-digit",
83+
})}
84+
</Button>
85+
</div>
86+
<div style={{ position: "absolute" }}>
87+
<MuiPickersUtilsProvider utils={DayJSUtils}>
88+
<DateTimePicker
89+
value={scheduleDate}
90+
inputVariant="outlined"
91+
style={{ height: 40, width: 200, opacity: 0, zIndex: 50 }}
92+
onChange={(date) => setScheduleDate(date.toDate())}
93+
ampm={false}
94+
autoOk
95+
disablePast
96+
/>
97+
</MuiPickersUtilsProvider>
98+
</div>
99+
</div>
87100
</Tabs.Item>
88101
</Tabs>
89102
)

src/scheduleJobs.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,51 @@ const TelegramBot = require("node-telegram-bot-api")
55
const chatId = process.env.CHAT_ID
66

77
const bot = new TelegramBot(process.env.BOT_TOKEN, {
8-
polling: chatId === undefined,
8+
polling: chatId === undefined || chatId === "",
99
})
1010

11-
if (chatId === undefined) {
11+
if (chatId === undefined || chatId === "") {
1212
bot.onText(/\/get_chat_id/, (msg, _match) => {
1313
bot.sendMessage(msg.chat.id, msg.chat.id)
1414
})
15-
}
16-
17-
// Send messages in queue every minute
18-
sendMessagesInQueue()
19-
scheduleJob()
15+
} else {
16+
// Send messages in queue every minute
17+
sendMessagesInQueue()
18+
scheduleJob()
2019

21-
function sendMessagesInQueue() {
22-
const db = new loki("./db/notifybot.db")
23-
db.loadDatabase({}, () => {
24-
const messages =
25-
db.getCollection("messages") || db.addCollection("messages")
26-
messages.findAndUpdate(
27-
{
28-
sent: false,
29-
schedule: {
30-
$lte: new Date(Date.now() + 58 * 1000).toISOString(),
20+
function sendMessagesInQueue() {
21+
const db = new loki("./db/notifybot.db")
22+
db.loadDatabase({}, () => {
23+
const messages =
24+
db.getCollection("messages") || db.addCollection("messages")
25+
messages.findAndUpdate(
26+
{
27+
sent: false,
28+
schedule: {
29+
$lte: new Date(Date.now() + 58 * 1000).toISOString(),
30+
},
3131
},
32-
},
33-
(obj) => {
34-
try {
35-
bot.sendMessage(chatId, obj.message)
36-
obj.sent = true
37-
return obj
38-
} catch (e) {
39-
console.log("Couldn't send message")
40-
console.log(e)
41-
obj.sent = false
42-
return obj
32+
(obj) => {
33+
try {
34+
bot.sendMessage(chatId, obj.message)
35+
obj.sent = true
36+
return obj
37+
} catch (e) {
38+
console.log("Couldn't send message")
39+
console.log(e)
40+
obj.sent = false
41+
return obj
42+
}
4343
}
44-
}
45-
)
46-
db.save()
47-
})
48-
}
44+
)
45+
db.save()
46+
})
47+
}
4948

50-
function scheduleJob() {
51-
schedule.scheduleJob("* * * * *", async () => {
52-
console.log("HELLO AT ", new Date())
53-
sendMessagesInQueue()
54-
})
49+
function scheduleJob() {
50+
schedule.scheduleJob("* * * * *", async () => {
51+
console.log("HELLO AT ", new Date())
52+
sendMessagesInQueue()
53+
})
54+
}
5555
}

0 commit comments

Comments
 (0)