Telegram API
마지막 업데이트
github.com/go-telegram/bot v1.20.0을 기반으로 한 github.com/pardnchiu/go-bot/core/telegram의 모든 exported 심볼입니다.타입
| 심볼 | 정의 | 비고 |
|---|---|---|
Bot | struct(비공개 필드) | New로 생성. 메서드는 동시 사용에 안전 |
Status | struct { Running bool; Username string; UserID int64 } | Status()가 반환 |
Input | struct | 필드: ChatID int64, ChatName string, MessageID int, UserID int64, Username string, Text string, Caption string, Photo []models.PhotoSize, Document *models.Document, CallbackData string, CallbackPicks []string, Raw *models.Update. Telegram 설정 참고 |
ReplyHandler | func(ctx context.Context, input Input) string | |
ChatStatus | struct(비공개 필드) | SendStatus가 관리하는 채팅별 상태 항목. 호출자가 만들지 않음 |
Option | func(*options) | New의 옵션 |
MessageOption | func(*messageOptions) | Send, SendInput, SendSelect, SendMultiSelect의 옵션 |
StatusOption | func(*statusOptions) | SendStatus의 옵션 |
SendType | int | 상수 TypeMarkdown(MarkdownV2), TypeHTML |
Command | struct { Name string; Description string } | SetCommands의 항목 하나. Name에는 앞의 /를 붙이지 않음. Telegram 설정 참고 |
FileType | int | 상수 TypeDocument, TypeVideo, TypeAudio |
생성자와 옵션
| 함수 | 효과 |
|---|---|
New(token string, opts ...Option) (*Bot, error) | token이 비어 있거나 SDK의 getMe 확인(타임아웃 5초)이 실패하면 오류 |
WithHTTPClient(client *http.Client) Option | polling과 업로드용 HTTP 클라이언트 |
WithPollTimeout(d time.Duration) Option | getUpdates의 long poll 타임아웃 |
WithSendType(t SendType) MessageOption | 메시지 텍스트의 parse mode |
WithStatusEmoji(emoji string) StatusOption | 리액션 이모지. 기본값 🤔 |
WithStatusSendType(t SendType) StatusOption | 상태 텍스트의 parse mode |
메서드
| 메서드 | 반환값 | 오류와 제한 |
|---|---|---|
Start(ctx context.Context) | error | GetMe 실패 |
Close() | error | 항상 nil |
Status() | Status | |
Reply(handler ReplyHandler) | — | 이전 handler를 대체 |
Send(ctx, chatID int64, replyTo int, text string, opts ...MessageOption) | (*models.Message, error) | API 오류 |
Delete(ctx, chatID int64, msgID int) | error | API 오류 |
SendFile(ctx, chatID int64, fileType FileType, path string, caption ...string) | (*models.Message, error) | 빈 경로, os.Open 실패, 알 수 없는 FileType |
SendPhoto(ctx, chatID int64, paths []string, caption ...string) | ([]*models.Message, error) | 비어 있지 않은 경로가 0개이거나 10개 초과 |
SendVoice(ctx, chatID int64, path string, caption ...string) | (*models.Message, error) | 빈 경로, os.Open 실패 |
SendInput(ctx, chatID int64, replyTo int, text string, opts ...MessageOption) | (*models.Message, error) | 빈 텍스트 |
SendSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption) | (*models.Message, error) | 빈 텍스트, 비어 있지 않은 항목 없음 |
SendMultiSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption) | (*models.Message, error) | 빈 텍스트, 비어 있지 않은 항목 없음, 예약 항목 __bot_multiselect_done__ |
SendStatus(ctx, chatID int64, replyTo int, text string, opts ...StatusOption) | error | 즉시 flush된 경우의 전송/수정 오류 |
FinishStatus(ctx, chatID int64) | error | 삭제 오류, 또는 진행 중인 수정을 기다리는 동안의 ctx.Err() |
SetCommands(ctx, commands []Command) | error | 빈 Name 또는 Description([Invalid]), setMyCommands 실패([Upstream]) |
Save(ctx, fileID, dir string) | (string, error) | 빈 인자, 20 MiB를 넘는 파일, 200이 아닌 HTTP 상태, 파일 시스템 오류 |
관련 페이지
Telegram 설정 · Telegram 메시지 · Telegram 인터랙션 · 상태 메시지 · 미디어 저장