Overview
TheOCTypes module defines the core type interfaces used by the OpenChat Bot SDK. It provides type-safe abstractions over the OpenChat canister APIs, ensuring proper integration patterns.
Type Definitions
PublicSummaryResponse
Response type for public group summary requests.Result of requesting public group information
OCService
The main service interface type defining all OpenChat bot operations.Type Patterns
Canister ID Pattern
All methods accept canister IDs asText (Principal in text format):
Result Pattern
All async operations returnResult.Result<T, Text> for consistent error handling:
Optional Fields Pattern
Many fields use Motoko’s optional type (?T) for nullable values:
Async Star Pattern
Methods useasync* to enable composition in async contexts:
OpenChat Canister Types
The service wraps several OpenChat canister types:UserIndexCanister
Manages user registration and profiles. Methods used:c2c_register_bot- Register new botuser- Query user informationc2c_set_avatar- Set user/bot avatar
GroupIndexCanister
Manages group chats. Methods used:public_summary- Get group informationsend_message_v2- Send group messagesedit_message_v2- Edit group messagesmessages_by_message_index- Retrieve specific messages
CommunityIndexCanister
Manages communities and channels. Methods used:summary- Get community informationjoin_community- Join a communityjoin_channel- Join a channelsend_message- Send channel messagesedit_message- Edit channel messages
LocalUserIndexCanister
Local user operations. Methods used:join_group- Join a group
Type Safety
The type system ensures:- Canister ID validation - Principal types prevent invalid references
- Message content validation - Variant types ensure valid message formats
- Response handling - Exhaustive pattern matching on response variants
- Optional field handling - Explicit handling of nullable values
Integration Guidelines
Type Imports
Service Type Usage
You can use theOCService type to define interfaces:
Custom Type Extensions
Extend types for your bot’s specific needs:Error Handling Convention
All service methods follow this convention:SuccessType- The specific OpenChat API response typeText- Error message from exception handling
#Success, #AlreadyInGroup, etc.)
Error case (#err) contains the exception message as text.