Skip to content

Commit 3b4d2a1

Browse files
authored
Merge pull request #1 from CilginSinek/main
Add GitHub Actions workflows for publishing to GitHub Packages and np…
2 parents 0cfa9cb + 54ef4ca commit 3b4d2a1

8 files changed

Lines changed: 697 additions & 2 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish to GitHub Packages
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish-gpr:
9+
name: GitHub Packages publish
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set Scope Name
21+
run: |
22+
sed -i 's/"name": "topluyo-bot"/"name": "@topluyo\/topluyo-bot"/' package.json
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '18'
28+
registry-url: 'https://npm.pkg.github.com'
29+
scope: '@${{ github.repository_owner }}'
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Publish package
35+
run: npm publish --access public
36+
env:
37+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/npm-publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish-npm:
9+
name: npm publish
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
registry-url: 'https://registry.npmjs.org'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Publish package
29+
run: npm publish --access public
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 178 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,178 @@
1-
# TopluyoBOTJS
2-
Topluyo Bot'un node.js için geliştirilmiş kütüphanesi
1+
# TopluyoBOT – Bot Dokümantasyonu
2+
**Versiyon:** 1.0.0  **Dil:** Türkçe
3+
**Oluşturulma Tarihi:** 2026‑03‑04
4+
5+
---
6+
7+
## 1. Giriş
8+
TopluyoBOT, Topluyo.com API’sine bağlanarak otomatik mesajlaşma, post ekleme, grup yönetimi ve form‑tamamlama işlemlerini gerçekleştirebilen bir Node.js kütüphanesidir.
9+
Bu dokümantasyon, botu **Kurulum → Kullanım → Olaylar → Eylemler → Örnekler** adımlarıyla tanıtır.
10+
11+
> **Not:** Topluyo hesabınızın “Cihazlarım” bölümünde oluşturulan bir **Token** gereklidir. Token dosyası `./.token.json` şeklinde, `"<YOUR_TOKEN>"` formatında olmalıdır.
12+
13+
---
14+
## 2. Kurulum
15+
16+
1. **Node.js** kurulu olduğundan emin olun (`node --version`).
17+
18+
2. Proje klasörünü oluşturup içerisine `nodejs` klasörünü indirin.
19+
20+
3. Token dosyasını oluşturun (`.token.json`):
21+
22+
```json
23+
"YOUR_TOPLUYO_TOKEN"
24+
```
25+
26+
5. Bot dosyanızı (`bot.js`) aşağıdaki gibi oluşturun (örnek kod):
27+
28+
```js
29+
// bot.js
30+
const TOKEN = require("./.token.json");
31+
const TopluyoBOT = require("./TopluyoBOT");
32+
const bot = TopluyoBOT(TOKEN);
33+
34+
// Genel olay yakalama
35+
bot.on("*", (event, data) => {
36+
if (event !== "message") console.log(event, data);
37+
});
38+
39+
// Mesaj olaylarını işleme
40+
bot.on("message", (message) => {
41+
console.log(message);
42+
43+
// Post ekleme
44+
if (message.action === "post/add") {
45+
if (message.message === "!test") {
46+
bot.post("/!api/post/add", {
47+
channel_id: message.channel_id,
48+
text: "Aktifim ⚡"
49+
}).then(e => console.log("Post gönderildi", e));
50+
} else {
51+
bot.post("/!api/post/add", {
52+
channel_id: message.channel_id,
53+
text: `sen bana \`${message.message}\` mı dedin?`
54+
});
55+
}
56+
}
57+
58+
// Grubla ilgili olaylar
59+
if (message.action === "group/join")
60+
console.log(message.user_id, "sunucuya katıldı");
61+
if (message.action === "group/leave")
62+
console.log(message.user_id, "sunucudan ayrıldı");
63+
if (message.action === "group/kick")
64+
console.log(message.user_id, "sunucudan atıldı");
65+
66+
// Bumıte ait olay
67+
if (message.action === "post/bumote") {
68+
console.log(`${message.post_id} üzerinde bir bumote gönderildi`, message.message);
69+
}
70+
});
71+
72+
```
73+
74+
6. Botu çalıştırın:
75+
76+
```bash
77+
node bot.js
78+
```
79+
80+
---
81+
82+
## 3. Olay (Event) Sistemi
83+
84+
| Olay Adı | Açıklama | Örnek Veri |
85+
|----------|----------|------------|
86+
| **open** | Bağlantı açıldığında tetiklenir. | `{}` |
87+
| **auth_problem** | Token bağlantısı geçerli değil ise | `{}` |
88+
| **connected** | WebSocket üzerinden bağlanıldığında tetiklenir. | `{}` |
89+
| **message** | Her türlü mesaj/işlem geldiğinde tetiklenir. | `{action: "...", ...}` |
90+
| **error** | Bağlantı veya API hataları. | `{}` |
91+
| **close** | Bağlantı kapandığında. | {} |
92+
93+
> **Not**: `message` olayı içinde `action` alanı, işlemin türünü belirler (aşağıda detaylı anlatılmıştır).
94+
95+
---
96+
97+
## 4. Eylemler (Actions)
98+
99+
### 4.1. `post/add`
100+
> **Açıklama** – Yeni bir post geldiğinde çalışır.
101+
102+
### 4.2. `post/bumote`
103+
> **Açıklama** – Bir postun üstüne “bumote” (form gönderildiğinde) eklenir.
104+
105+
**Message İçeriği (Örnek)**
106+
```json
107+
{
108+
"action": "post/bumote",
109+
"message": {
110+
"form": {
111+
"name": "Hasan ",
112+
"burc": "Koç"
113+
},
114+
"submit": "Gönder"
115+
},
116+
"post_id": 61406,
117+
"user_id": 8000
118+
}
119+
```
120+
121+
**İşlem Örneği**
122+
```js
123+
if (message.action === "post/bumote") {
124+
const form = message.message.form; // {name: "...", burc: "..."}
125+
// form.name, form.burc kullanabilirsiniz
126+
console.log(`Kullanıcı ${form.name} (${form.burc}) formu gönderdik.`);
127+
}
128+
```
129+
130+
### 4.3. `message/send`
131+
> **Açıklama** – Kullanıcıdan gelen normal mesaj.
132+
> **Kullanım** – Bot, gelen mesajı okuyabilir, yanıt gönderebilir.
133+
134+
| Alan | Tip | Açıklama |
135+
|------|-----|----------|
136+
| `user_id` | `number` | Mesajı gönderen kullanıcı ID’si. |
137+
| `message` | `string` | Gönderilen metin. |
138+
139+
### 4.4. Grup İlişkili Eylemler
140+
| Action | Açıklama | Örnek |
141+
|--------|----------|-------|
142+
| `group/join` | Kullanıcı grup (sunucu) katıldı. | `{action:"group/join", group_id:3253, user_id:17}` |
143+
| `group/leave` | Kullanıcı grup (sunucu) ayrıldı. | `{action:"group/leave", group_id:3253, user_id:17}` |
144+
| `group/kick` | Kullanıcı grup (sunucu) dışarı atıldı. | `{action:"group/kick", group_id:3253, user_id:17}` |
145+
146+
---
147+
148+
## 5. Örnek Senaryolar
149+
150+
| Senaryo | Açıklama | Kod |
151+
|---------|----------|-----|
152+
| **Test Komutu** | `!test` yazıldığında bot “Aktifim ⚡” postu gönderir. | Yukarıdaki `if(message.message==="!test")` bloğu. |
153+
| **Yazılı Post** | Kullanıcı başka metin gönderdiğinde bot “sen bana `[metin]` mı dedin?” postu oluşturur. | `else` bloğundaki `bot.post` çağrısı. |
154+
| **Form Eylemi** | Kullanıcı bir form gönderdiğinde bu form verileri okunur. | `if(message.action==="post/bumote")` bloğu. |
155+
| **Grup Katılım** | Kullanıcı gruba katıldığında log kaydedilir. | `if(message.action==="group/join")` bloğu. |
156+
157+
---
158+
159+
## 6. Hata Yönetimi
160+
161+
| Hata Durumu | Açıklama | Önerilen Çözüm |
162+
|-------------|----------|----------------|
163+
| `token` eksik | Token dosyası bulunamadı. | `.token.json` dosyasını kontrol edin. |
164+
| `auth_problem` | Token geçersiz. | Token’ı yeniden oluşturun. |
165+
| `api error` | API yanıtı 4xx/5xx. | API dökümantasyonuna göz atın, rate limit kontrolü yapın. |
166+
167+
> **İpucu**: Hata olaylarını dinleyebilirsiniz:
168+
```js
169+
bot.on("error", (err) => console.error("Bot Hatası:", err));
170+
```
171+
172+
---
173+
174+
## 7. Sonuç
175+
176+
Topluyo API Dökümantasyonuna: https://topluyo.com/!api adresinden ulaşabilirsiniz =)
177+
178+
İyi kodlamalar! 🚀

index.d.mts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/// <reference types="node" />
2+
3+
import type WebSocket from 'ws';
4+
5+
/**
6+
* Represents the bot instance returned by TopluyoBOT()
7+
*/
8+
export interface BotInstance {
9+
/** The underlying WebSocket connection */
10+
ws: WebSocket;
11+
12+
/**
13+
* Send a single API request to the Topluyo platform
14+
* @param api API endpoint name
15+
* @param data Request payload
16+
*/
17+
post(api: string, data?: Record<string, any>): Promise<any>;
18+
19+
/** Fired when the WebSocket connection is opened */
20+
on(event: 'open', callback: (this: BotInstance) => void): void;
21+
/** Fired when the bot is successfully authenticated */
22+
on(event: 'connected', callback: (this: BotInstance) => void): void;
23+
/** Fired when the WebSocket connection is closed */
24+
on(event: 'close', callback: (this: BotInstance) => void): void;
25+
/** Fired when authentication fails */
26+
on(event: 'auth_problem', callback: (this: BotInstance) => void): void;
27+
/** Fired when a message is received */
28+
on(event: 'message', callback: (this: BotInstance, data: any) => void): void;
29+
/** Fired when a WebSocket error occurs */
30+
on(event: 'error', callback: (this: BotInstance, err: Error) => void): void;
31+
/**
32+
* Wildcard listener — receives all events.
33+
* The first argument is the event name, the second is the event data.
34+
*/
35+
on(event: '*', callback: (this: BotInstance, event: string, data: any) => void): void;
36+
37+
/** Opens the WebSocket connection (called automatically on construction) */
38+
connect(): void;
39+
}
40+
41+
/**
42+
* Creates and connects a new TopluyoBOT instance
43+
* @param token Bot authentication token
44+
* @returns Connected BotInstance
45+
*
46+
* @example
47+
* // ES Module
48+
* import TopluyoBOT from 'topluyo-bot';
49+
* const bot = TopluyoBOT('your-token');
50+
*
51+
* bot.on('message', function(data) {
52+
* console.log(data);
53+
* });
54+
*/
55+
declare function TopluyoBOT(token: string): BotInstance;
56+
57+
export { TopluyoBOT };
58+
export default TopluyoBOT;

index.d.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/// <reference types="node" />
2+
3+
import WebSocket = require('ws');
4+
5+
/**
6+
* Represents the bot instance returned by TopluyoBOT()
7+
*/
8+
export interface BotInstance {
9+
/** The underlying WebSocket connection */
10+
ws: WebSocket;
11+
12+
/**
13+
* Send a single API request to the Topluyo platform
14+
* @param api API endpoint name
15+
* @param data Request payload
16+
*/
17+
post(api: string, data?: Record<string, any>): Promise<any>;
18+
19+
/** Fired when the WebSocket connection is opened */
20+
on(event: 'open', callback: (this: BotInstance) => void): void;
21+
/** Fired when the bot is successfully authenticated */
22+
on(event: 'connected', callback: (this: BotInstance) => void): void;
23+
/** Fired when the WebSocket connection is closed */
24+
on(event: 'close', callback: (this: BotInstance) => void): void;
25+
/** Fired when authentication fails */
26+
on(event: 'auth_problem', callback: (this: BotInstance) => void): void;
27+
/** Fired when a message is received */
28+
on(event: 'message', callback: (this: BotInstance, data: any) => void): void;
29+
/** Fired when a WebSocket error occurs */
30+
on(event: 'error', callback: (this: BotInstance, err: Error) => void): void;
31+
/**
32+
* Wildcard listener — receives all events.
33+
* The first argument is the event name, the second is the event data.
34+
*/
35+
on(event: '*', callback: (this: BotInstance, event: string, data: any) => void): void;
36+
37+
/** Opens the WebSocket connection (called automatically on construction) */
38+
connect(): void;
39+
}
40+
41+
/**
42+
* Creates and connects a new TopluyoBOT instance
43+
* @param token Bot authentication token
44+
* @returns Connected BotInstance
45+
*
46+
* @example
47+
* // CommonJS
48+
* const TopluyoBOT = require('topluyo-bot');
49+
* const bot = TopluyoBOT('your-token');
50+
*
51+
* bot.on('message', function(data) {
52+
* console.log(data);
53+
* });
54+
*/
55+
declare function TopluyoBOT(token: string): BotInstance;
56+
57+
export = TopluyoBOT;

0 commit comments

Comments
 (0)