Telegram Integration API
The Telegram Integration API enables users to connect their accounts with Telegram for receiving notifications and support communication. This feature provides a seamless way to receive updates and communicate with support through Telegram.
Overview
The API provides several key operations:
- Register Telegram Account
- Send/Receive Support Messages
- Manage Notification Preferences
- Test Connection Status
- Admin Support Interface
Flow Diagram
sequenceDiagram
participant User
participant Bot
participant API
participant Admin
participant Database
User->>Bot: 1. Start chat (/start)
Bot->>Database: Store chat ID
Bot-->>User: Welcome message
User->>API: 2. Register username
API->>Database: Link account
API->>Bot: Send verification
Bot-->>User: Verify connection
User->>Bot: 3. Send support message
Bot->>Database: Store message
Bot->>Admin: Forward to support
Admin->>Bot: Reply to message
Bot-->>User: Deliver reply
API Reference
Register Telegram Account
Links a Telegram username with the user's account.
mutation RegisterTelegram($registration: TelegramRegistration!) {
registerTelegram(registration: $registration) {
success
message
}
}
Variables
{
"registration": {
"username": "user_telegram_name",
"verificationCode": "123456"
}
}
Test Connection
Tests the Telegram connection for a user.
mutation TestTelegramConnection($chatId: String!) {
testTelegramConnection(chatId: $chatId)
}
Update Telegram Info
Updates a user's Telegram information.
mutation UpdateTelegramInfo($username: String!, $chatId: String!) {
updateTelegramInfo(username: $username, chatId: $chatId) {
telegramUsername
telegramChatId
}
}
Send Notification
Sends a Telegram notification to a user (Admin only).
mutation SendTelegramNotification(
$userId: Int
$username: String
$message: String!
) {
sendTelegramNotification(
userId: $userId
username: $username
message: $message
)
}
Get Message History
Retrieves message history for a user.
query GetTelegramMessages($userId: ID!, $page: Int, $size: Int) {
getTelegramMessages(userId: $userId, page: $page, size: $size) {
id
message
timestamp
direction
status
adminUsername
}
}
Implementation Guide
User Registration Flow
-
User starts bot interaction:
- Find @OrbVPNbot on Telegram
- Send /start command
- Bot stores chat ID
-
Register account:
const response = await client.mutate({
mutation: gql`
mutation Register($registration: TelegramRegistration!) {
registerTelegram(registration: $registration)
}
`,
variables: {
registration: {
username: telegramUsername,
verificationCode: code,
},
},
});