Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
duament committed Nov 21, 2024
0 parents commit ff5156a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cf-worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v4
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
30 changes: 30 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT

async function forward_message(env, chat_id, from_chat_id, message_id) {
const url = `https://api.telegram.org/bot${env.TG_BOT_TOKEN}/sendMessage`
const data = {
chat_id,
from_chat_id,
message_id,
}
const response = await fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
})
console.log(data)
if (!response.ok) {
throw new Error(`send_message: server returns ${response.status} ${response.statusText}`)
}
}

export default {
async scheduled(event, env, ctx) {
await forward_message(env, env.CHAT_ID, env.FROM_CHAT_ID, env.MESSAGE_ID)

console.log('cron processed')
},
};
6 changes: 6 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "tgbot-cron"
main = "bot.js"
compatibility_date = "2024-08-06"

[triggers]
crons = ["0 11,16 * * *"]

0 comments on commit ff5156a

Please sign in to comment.