@codebam/cf-workers-telegram-bot 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -26
- package/dist/main/src/telegram_bot.js +6 -4
- package/dist/worker/src/worker.js +4 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<h3 align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/codebam/cf-workers-telegram-bot/master/assets/logo.png" width="100" />
|
|
3
|
+
<br/>
|
|
4
|
+
CF workers telegram bot
|
|
5
|
+
<br/>
|
|
6
|
+
</h3>
|
|
7
|
+
|
|
8
|
+
<h6 align="center">
|
|
9
|
+
<a href="https://github.com/codebam/cf-workers-telegram-bot/wiki">Wiki</a>
|
|
10
|
+
·
|
|
11
|
+
<a href="https://codebam.github.io/cf-workers-telegram-bot-docs/">Docs</a>
|
|
12
|
+
</h6>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://github.com/codebam/cf-workers-telegram-bot/stargazers"> <img src="https://img.shields.io/github/stars/codebam/cf-workers-telegram-bot?style=for-the-badge&logo=starship&color=111111&logoColor=ffffff&labelColor=000000" alt="GitHub stars"/></a>
|
|
16
|
+
<a href="https://github.com/codebam/cf-workers-telegram-bot/issues">
|
|
17
|
+
<img src="https://img.shields.io/github/issues/codebam/cf-workers-telegram-bot?style=for-the-badge&logo=gitbook&color=111111&logoColor=ffffff&labelColor=000000" alt="GitHub issues"/></a>
|
|
18
|
+
<a href="https://github.com/codebam/cf-workers-telegram-bot"> <img src="https://img.shields.io/github/forks/codebam/cf-workers-telegram-bot?style=for-the-badge&logo=git&color=111111&logoColor=ffffff&labelColor=000000" alt="GitHub forks"/></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@codebam/cf-workers-telegram-bot"> <img src="https://img.shields.io/npm/v/@codebam/cf-workers-telegram-bot?style=for-the-badge&logo=npm&color=111111&logoColor=ffffff&labelColor=000000" alt="npm version" /></a>
|
|
20
|
+
</p>
|
|
4
21
|
|
|
5
22
|

|
|
6
23
|
|
|
7
|
-
serverless telegram bot on cf workers
|
|
8
|
-
|
|
9
|
-
To get continuous conversation with AI working make sure you add a database
|
|
10
|
-
to your wrangler.toml and initailize it with the schema.sql
|
|
11
|
-
|
|
12
24
|
```sh
|
|
13
25
|
npm i @codebam/cf-workers-telegram-bot
|
|
14
26
|
```
|
|
15
27
|
|
|
16
|
-
See `worker.ts`
|
|
28
|
+
See `worker.ts` for an example of what a bot might look like. Just import from `@codebam/cf-workers-telegram-bot`.
|
|
29
|
+
|
|
30
|
+
- `npm create cloudflare@latest`
|
|
31
|
+
- `npx wrangler login`
|
|
32
|
+
- `npx wrangler secret put SECRET_TELEGRAM_API_TOKEN`, set it to your telegram bot token that you got from `@BotFather`
|
|
33
|
+
- `npx wrangler deploy`
|
|
34
|
+
- Open this url in your browser to set your webhook `https://your-worker.username.workers.dev/SECRET_TELEGRAM_API_TOKEN?command=set`
|
|
35
|
+
|
|
36
|
+
To set up GitHub actions to deploy when you push, see https://github.com/cloudflare/wrangler-action
|
|
17
37
|
|
|
18
38
|
---
|
|
19
39
|
|
|
20
|
-
|
|
40
|
+
These instructions are for if you want to deploy a copy of the bot along with
|
|
41
|
+
the library. Such as if you need extra API requests that haven't been
|
|
42
|
+
implemented yet.
|
|
43
|
+
|
|
44
|
+
[](https://deploy.workers.cloudflare.com/?url=https://github.com/codebam/cf-workers-telegram-bot)
|
|
21
45
|
|
|
22
46
|
- Click the deploy button
|
|
23
47
|
- Navigate to your new **GitHub repository > Settings > Secrets** and add the following secrets:
|
|
@@ -31,19 +55,3 @@ To use the deploy button:
|
|
|
31
55
|
```
|
|
32
56
|
|
|
33
57
|
- Push to `master` to trigger a deploy
|
|
34
|
-
|
|
35
|
-
To fork this repo and use wrangler:
|
|
36
|
-
|
|
37
|
-
- Click fork
|
|
38
|
-
- `npm i -g wrangler`
|
|
39
|
-
- `wrangler secret put SECRET_TELEGRAM_API_TOKEN` and set it to your telegram
|
|
40
|
-
bot token
|
|
41
|
-
- `wrangler d1 create llama2`
|
|
42
|
-
- put the database block from the command in your wrangler.toml
|
|
43
|
-
- `wrangler d1 execute --remote llama2 --file ./schema.sql`
|
|
44
|
-
- `wrangler deploy`
|
|
45
|
-
- Done!
|
|
46
|
-
|
|
47
|
-
## Getting started with cf-workers-telegram-bot
|
|
48
|
-
|
|
49
|
-
Once you've deployed the bot you can get your Webhook command URL by calling `await bot.webhook.set()`
|
|
@@ -13,9 +13,11 @@ export default class TelegramBot {
|
|
|
13
13
|
this.update_type = '';
|
|
14
14
|
}
|
|
15
15
|
on(event, callback) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (event !== 'on') {
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
// @ts-ignore TS7053
|
|
19
|
+
this[event] = callback;
|
|
20
|
+
}
|
|
19
21
|
return this;
|
|
20
22
|
}
|
|
21
23
|
async handle(request) {
|
|
@@ -60,7 +62,7 @@ export default class TelegramBot {
|
|
|
60
62
|
}
|
|
61
63
|
// eslint-disable-next-line
|
|
62
64
|
// @ts-ignore
|
|
63
|
-
if (!this[command]) {
|
|
65
|
+
if (!this[command] || command === 'on') {
|
|
64
66
|
command = 'default';
|
|
65
67
|
}
|
|
66
68
|
// eslint-disable-next-line
|
|
@@ -62,11 +62,10 @@ export default {
|
|
|
62
62
|
.on('default', async function () {
|
|
63
63
|
switch (bot3.update_type) {
|
|
64
64
|
case 'inline': {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
65
|
+
const translated_text = await fetch('https://clients5.google.com/translate_a/t?client=at&sl=auto&tl=en&q=' +
|
|
66
|
+
encodeURIComponent(bot3.update.inline_query?.query.toString() ?? ''))
|
|
67
|
+
.then((r) => r.json())
|
|
68
|
+
.then((json) => json[0].slice(0, -1).join(' '));
|
|
70
69
|
await bot3.reply(translated_text ?? '');
|
|
71
70
|
break;
|
|
72
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebam/cf-workers-telegram-bot",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "serverless telegram bot on cf workers",
|
|
5
5
|
"main": "./dist/main/src/main.js",
|
|
6
6
|
"module": "./dist/main/src/main.js",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"@typescript-eslint/parser": "^7.8.0",
|
|
36
36
|
"eslint": "^9.2.0",
|
|
37
37
|
"eslint-config-prettier": "^9.1.0",
|
|
38
|
-
"globals": "^15.
|
|
38
|
+
"globals": "^15.2.0",
|
|
39
39
|
"lerna": "^8.1.2",
|
|
40
40
|
"prettier": "^3.2.5",
|
|
41
41
|
"typescript": "^5.4.5",
|
|
42
42
|
"typescript-eslint": "^7.8.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5a413513b05d2cde80b76d4e901dbe334e95ed25"
|
|
45
45
|
}
|