Skip to content

Commit 1b1a915

Browse files
committed
chore: add PostHog plugin docs
1 parent 612bb21 commit 1b1a915

File tree

5 files changed

+270
-1
lines changed

5 files changed

+270
-1
lines changed

docs/.vitepress/config/locales/en.locale.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export const localeEn = {
6666
text: "Media group",
6767
link: "/plugins/official/media-group",
6868
},
69+
{
70+
text: "PostHog",
71+
link: "/plugins/official/posthog",
72+
},
6973
{
7074
text: "Prompt",
7175
link: "/plugins/official/prompt",

docs/.vitepress/config/locales/ru.locale.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export const localeRu = {
9393
text: "Медиа группы",
9494
link: "/ru/plugins/official/media-group",
9595
},
96+
{
97+
text: "PostHog",
98+
link: "/ru/plugins/official/posthog",
99+
},
96100
{
97101
text: "Prompt",
98102
link: "/ru/plugins/official/prompt",

docs/plugins/official/posthog.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# PostHog
2+
3+
<div class="badges">
4+
5+
[![npm](https://img.shields.io/npm/v/@gramio/posthog?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/posthog)
6+
[![JSR](https://jsr.io/badges/@gramio/posthog)](https://jsr.io/@gramio/posthog)
7+
[![JSR Score](https://jsr.io/badges/@gramio/posthog/score)](https://jsr.io/@gramio/posthog)
8+
9+
</div>
10+
11+
A plugin that conveniently wraps the [PostHog](https://posthog.com/) client. Automatically catches errors (including `senderId` and `chatId` in them). Provides methods with pre-bound distinctId (as `from.id`).
12+
13+
### Installation
14+
15+
::: code-group
16+
17+
```bash [npm]
18+
npm install @gramio/media-group
19+
```
20+
21+
```bash [yarn]
22+
yarn add @gramio/media-group
23+
```
24+
25+
```bash [pnpm]
26+
pnpm add @gramio/media-group
27+
```
28+
29+
```bash [bun]
30+
bun install @gramio/media-group
31+
```
32+
33+
:::
34+
35+
### Usage
36+
37+
```typescript
38+
import { PostHog } from "posthog-node";
39+
import { posthogPlugin } from "@gramio/posthog";
40+
import { Bot } from "gramio";
41+
42+
const posthog = new PostHog(process.env.POSTHOG_API_KEY!, {
43+
host: process.env.POSTHOG_HOST,
44+
});
45+
46+
const bot = new Bot(process.env.BOT_TOKEN!)
47+
.extend(posthogPlugin(posthog))
48+
.on("message", (context) => {
49+
context.capture("message", {
50+
text: context.message.text,
51+
});
52+
53+
throw new Error("Will be caught by PostHog");
54+
});
55+
56+
await bot.start();
57+
```
58+
59+
## Methods
60+
61+
### `capture(event: string, properties?: Record<string, unknown>)`
62+
63+
Captures events and sends them to PostHog along with `senderId`.
64+
65+
```typescript
66+
context.capture("message", {
67+
text: context.message.text,
68+
});
69+
```
70+
71+
### Feature Flags
72+
73+
#### `isEnabled(feature: string, options?: IsFeatureEnabledOptions)`
74+
75+
Checks if a feature flag is enabled for the current user.
76+
77+
```typescript
78+
const isEnabled = await context.featureFlags.isEnabled("beta-feature", {
79+
groups: { organization: "org_id" },
80+
});
81+
// Returns boolean
82+
```
83+
84+
#### `getPayload(feature: string, value?: GetFeatureFlagPayloadValue, options?: GetFeatureFlagPayloadOptions)`
85+
86+
Gets the payload (additional data) for a feature flag.
87+
88+
```typescript
89+
const payload = await context.featureFlags.getPayload("pricing-page", {
90+
sendEmail: true,
91+
});
92+
// Returns any | undefined
93+
```
94+
95+
#### `get(feature: string, options?: GetFeatureFlagOptions)`
96+
97+
Gets complete information about a feature flag.
98+
99+
```typescript
100+
const flag = await context.featureFlags.get("new-onboarding", {
101+
personProperties: { plan: "pro" },
102+
});
103+
// Returns boolean | string | number | Record<string, any>
104+
```
105+
106+
#### `getAll(options?: GetAllFlagsOptions)`
107+
108+
Gets all feature flags for the user.
109+
110+
```typescript
111+
const allFlags = await context.featureFlags.getAll({
112+
groups: { company: "acme" },
113+
});
114+
// Returns Record<string, boolean | string | number>
115+
```
116+
117+
#### `getAllPayload(options?: GetAllFlagsPayloadOptions)`
118+
119+
Gets all flags along with their payloads.
120+
121+
```typescript
122+
const flagsWithPayloads = await context.featureFlags.getAllPayload({
123+
personProperties: { country: "US" },
124+
});
125+
/* Returns:
126+
{
127+
flags: Record<string, boolean | string | number>
128+
payloads: Record<string, any>
129+
} */
130+
```

docs/ru/plugins/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ head:
2323
- [Авто-повтор](/ru/plugins/official/auto-retry)
2424
- [Кеш медиа](/ru/plugins/official/media-cache)
2525
- [Медиа группы](/ru/plugins/official/media-group)
26-
- [Prompt](/ru/plugins/official/prompt)
26+
- [PostHog](/ru/plugins/official/posthog)
27+
- [Prompt](/ru/plugins/official/prompt)
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Posthog
2+
3+
<div class="badges">
4+
5+
[![npm](https://img.shields.io/npm/v/@gramio/posthog?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/posthog)
6+
[![JSR](https://jsr.io/badges/@gramio/posthog)](https://jsr.io/@gramio/posthog)
7+
[![JSR Score](https://jsr.io/badges/@gramio/posthog/score)](https://jsr.io/@gramio/posthog)
8+
9+
</div>
10+
11+
Плагин, который удобно оборачивает клиент [PostHog](https://posthog.com/). Автоматически ловит ошибки (и включает в них `senderId` и `chatId`). Предоставляет методы к которым уже привязан distinctId (в виде `from.id`)
12+
13+
### Установка
14+
15+
::: code-group
16+
17+
```bash [npm]
18+
npm install @gramio/media-group
19+
```
20+
21+
```bash [yarn]
22+
yarn add @gramio/media-group
23+
```
24+
25+
```bash [pnpm]
26+
pnpm add @gramio/media-group
27+
```
28+
29+
```bash [bun]
30+
bun install @gramio/media-group
31+
```
32+
33+
:::
34+
35+
### Использование
36+
37+
```typescript
38+
import { PostHog } from "posthog-node";
39+
import { posthogPlugin } from "@gramio/posthog";
40+
import { Bot } from "gramio";
41+
42+
const posthog = new PostHog(process.env.POSTHOG_API_KEY!, {
43+
host: process.env.POSTHOG_HOST,
44+
});
45+
46+
const bot = new Bot(process.env.BOT_TOKEN!)
47+
.extend(posthogPlugin(posthog))
48+
.on("message", (context) => {
49+
context.capture("message", {
50+
text: context.message.text,
51+
});
52+
53+
throw new Error("Будет поймано PostHog");
54+
});
55+
56+
await bot.start();
57+
```
58+
59+
## Методы
60+
61+
### `capture(event: string, properties?: Record<string, unknown>)`
62+
63+
Ловит события и отправляет их в PostHog вместе с `senderId`.
64+
65+
```typescript
66+
context.capture("message", {
67+
text: context.message.text,
68+
});
69+
```
70+
71+
### Feature Flags
72+
73+
#### `isEnabled(feature: string, options?: IsFeatureEnabledOptions)`
74+
75+
Проверяет включен ли feature flag для текущего пользователя.
76+
77+
```typescript
78+
const isEnabled = await context.featureFlags.isEnabled("beta-feature", {
79+
groups: { organization: "org_id" },
80+
});
81+
// Возвращает boolean
82+
```
83+
84+
#### `getPayload(feature: string, value?: GetFeatureFlagPayloadValue, options?: GetFeatureFlagPayloadOptions)`
85+
86+
Получает payload (дополнительные данные) для feature flag.
87+
88+
```typescript
89+
const payload = await context.featureFlags.getPayload("pricing-page", {
90+
sendEmail: true,
91+
});
92+
// Возвращает any | undefined
93+
```
94+
95+
#### `get(feature: string, options?: GetFeatureFlagOptions)`
96+
97+
Получает полную информацию о feature flag.
98+
99+
```typescript
100+
const flag = await context.featureFlags.get("new-onboarding", {
101+
personProperties: { plan: "pro" },
102+
});
103+
// Возвращает boolean | string | number | Record<string, any>
104+
```
105+
106+
#### `getAll(options?: GetAllFlagsOptions)`
107+
108+
Получает все feature flags для пользователя.
109+
110+
```typescript
111+
const allFlags = await context.featureFlags.getAll({
112+
groups: { company: "acme" },
113+
});
114+
// Возвращает Record<string, boolean | string | number>
115+
```
116+
117+
#### `getAllPayload(options?: GetAllFlagsPayloadOptions)`
118+
119+
Получает все флаги вместе с их payloads.
120+
121+
```typescript
122+
const flagsWithPayloads = await context.featureFlags.getAllPayload({
123+
personProperties: { country: "US" },
124+
});
125+
/* Возвращает:
126+
{
127+
flags: Record<string, boolean | string | number>
128+
payloads: Record<string, any>
129+
} */
130+
```

0 commit comments

Comments
 (0)