Satori Universal Messenger Protocol

repository·main·Indexed 42 days ago

https://github.com/satorijs/satori

A Universal Messenger Protocol providing a unified interface for interacting with various messaging platforms through a plugin-based adapter system. Satori supports adapters for Discord, Telegram, Slack, Lark (飞书), LINE, Matrix, and DingTalk, allowing developers to manage multiple accounts and event listeners across different communication protocols.

Tokens
130.8K
Snippets
348
Records
560
Agent score
54%

What's inside Satori

  1. Install and use the Lark (飞书) adapter for Satori

    main

    The @satorijs/adapter-lark package provides an adapter for the Lark (飞书) messaging platform, allowing Satori-based applications to communicate via Lark.

    To use this adapter, you must install the package and integrate it into your Satori instance. Detailed configuration and platform-specific setup can be found in the official Lark adapter documentation.

  2. Specifying connection protocols in adapters

    main

    Some adapters, such as Telegram, support different connection methods. You can specify the protocol (e.g., 'server' or 'polling') within the adapter configuration object. When using the 'server' protocol, you typically need to provide a path and ensure your Context is configured with a port and selfUrl to handle incoming HTTP requests (often using a router plugin).

    import { Context } from '@satorijs/core'
    import router from '@cordisjs/plugin-server'
    import telegram from '@satorijs/adapter-telegram'
    
    // your application will be listening http://localhost:8080
    // and be available at https://example.com
    const ctx = new Context({
      port: 8080,
      selfUrl: 'https://example.com',
    })
    
    // you need a router plugin to handle http requests
    ctx.plugin(router)
    
    ctx.plugin(telegram, {
      // telegram supports two ways of connection: server and polling
      protocol: 'server',
      path: '/telegram',
      token: 'xxxxxx',
    })
  3. Basic usage of Satori

    main

    To use Satori, create a new Context from @satorijs/core, register an adapter (e.g., Discord) using ctx.plugin(), define event listeners like ctx.on('message', ...), and then call await ctx.start() to run the application.

    import { Context } from '@satorijs/core'
    import discord from '@satorijs/adapter-discord'
    
    // create a new context
    const ctx = new Context()
    
    // configure a Discord account
    ctx.plugin(discord, {
      token: 'xxxxxx',
    })
    
    // listen to message events
    ctx.on('message', (session) => {
      console.log(session.content)
    })
    
    // start application
    await ctx.start()
  4. Manage Lark Talent Data Structures

    main

    The Lark adapter provides extensive types for managing talent (candidate) information, including basic profiles, education, work experience, and customized data fields.

    Key interfaces include:

    • Talent: The root object for a candidate, containing basic_info, education_list, career_list, etc.
    • TalentBasicInfo: Core identity details like name, mobile, email, and nationality.
    • TalentEducationInfo: Details regarding academic background, including degree, school, and field_of_study.
    • TalentCareerInfo: Professional history including company, title, and start_time.
    • TalentCustomizedDataObjectValue: A flexible structure for handling custom fields via object_id and children.
    export interface Talent {
      /** 人才ID */
      id?: string
      /** 是否在猎头保护期 */
      is_in_agency_period?: boolean
      /** 是否已入职 */
      is_onboarded?: boolean
      /** 基础信息 */
      basic_info?: TalentBasicInfo
      /** 教育经历 */
      education_list?: TalentEducationInfo[]
      /** 工作经历 */
      career_list?: TalentCareerInfo[]
      /** 项目经历 */
      project_list?: TalentProjectInfo[]
      /** 作品 */
      works_list?: TalentWorksInfo[]
      /** 获奖 */
      award_list?: TalentAwardInfo[]
      /** 语言能力 */
      language_list?: TalentLanguageInfo[]
      /** 社交账号 */
      sns_list?: TalentSnsInfo[]
      /** 简历来源 */
      resume_source_list?: TalentResumeSource[]
      /** 面试登记表 */
      interview_registration_list?: TalentInterviewRegistrationSimple[]
      /** 简历附件id列表(按照简历创建时间降序) */
      resume_attachment_id_list?: string[]
      /** 最高学历 */
      top_degree?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
      /** 第一学历 */
      first_degree?: 1 | 2 | 3 | 4 | 5 | 6 | 7
    }
  5. Manage Profile Settings for Employees

    main

    The Lark adapter provides a comprehensive set of interfaces for managing employee profile data via ProfileSetting interfaces:

    • ProfileSettingPersonalInfo: The root interface for personal information, containing personal_basic_info, emergency_contacts, bank_accounts, nationals, dependents, hukou, and contact_addresses.
    • ProfileSettingEmploymentInfo: Contains basic_info, probation_info, employment_record, and emp_contract_record.
    • ProfileSettingCareer: Manages educations and work_experiences.
    • ProfileSettingDataAttachment: Manages personal_records and custom_groups.
  6. Understand the Event structure and EventName types

    main

    The protocol communicates via Event objects. An Event contains metadata like sn (sequence number), timestamp, platform, and selfId, along with payload data specific to the event type (e.g., message, user, guild, member).

    EventName defines the possible event types, which follow two patterns:

    1. Resource Actions: ${Genres}-${Actions} where Genres are friend, channel, guild, guild-member, guild-role, guild-file, or guild-emoji, and Actions are added, deleted, or updated.
    2. Direct Events: Specific strings like message, message-deleted, message-updated, message-pinned, message-unpinned, interaction/command, reaction-added, reaction-deleted, reaction-deleted/one, reaction-deleted/all, reaction-deleted/emoji, send, friend-request, guild-request, or guild-member-request.

    An Event payload can be treated as a MessageLike (either a Message or an Event).

  7. Access LINE event data in Session

    main
    When using the Line adapter, the @satorijs/core Session object is augmented with a line property. This property contains the WebhookEvent and Internal data specific to the LINE platform, allowing you to access event-specific metadata during message handling.
  8. Define Discord message components

    main

    When using the @satorijs/adapter-discord adapter, you can construct interactive messages using various component types. Components must be wrapped in an ActionRow to be sent in a message.

    Supported component types include:

    • Button: Clickable buttons.
    • SelectMenu: Menus for selecting options (including User, Role, Mentionable, and Channel selects).
    • TextInput: Text input fields for users to fill out.
    • ActionRow: A container that holds a collection of components.
    import { ActionRow, Button, ButtonStyles, ComponentType } from '@satorijs/adapter-discord';
    
    const row: ActionRow = {
      type: ComponentType.ACTION_ROW,
      components: [
        {
          type: ComponentType.BUTTON,
          style: ButtonStyles.PRIMARY,
          label: 'Click Me',
          custom_id: 'my_button_id'
        }
      ]
    };
  9. Understand Discord invite data structures

    main

    The Discord adapter uses several interfaces to represent invite data:

    Invite

    The base object representing a Discord invite.

    • code: The unique invite code.
    • channel: A partial Channel object.
    • guild: A partial Guild object.
    • inviter: The User who created the invite.
    • target_type: Invite.TargetType (1: STREAM, 2: EMBEDDED_APPLICATION).

    Invite.Metadata

    An extension of Invite containing usage statistics.

    • uses: Number of times used.
    • max_uses: Maximum allowed uses.
    • max_age: Duration in seconds before expiry.
    • temporary: Whether the invite grants temporary membership.
    • created_at: Creation timestamp.

    Invite.StageInstance

    Data for Stage channels.

    • members: List of GuildMember objects currently speaking.
    • participant_count: Total users in the Stage.
    • speaker_count: Users currently speaking.
    • topic: The Stage topic string.
  10. Handle QQ Message Audits

    main
    When sending messages to QQ, some messages may enter an audit state (returning a 304023 code). To handle this, ensure your bot has the MESSAGE_AUDIT intent enabled. The adapter provides an audit mechanism that listens for qq/message-audit-pass and qq/message-audit-reject events to resolve the message status.