SuperAPI AI 工具集

cometchat-android-v5-extensions

编程与开发

查看项目

更新于 10-15 20:15

技能介绍

用途:介绍 CometChat Android UI Kit 的扩展架构,说明扩展如何接入 UI Kit、有哪些内置扩展,以及如何编写自定义扩展。适用于处理 ExtensionsDataSource 或 ExtensionDecorator、添加自定义扩展、禁用扩展等场景。启用后端扩展或 AI 功能应改用 cometchat-android-v5-features;编写自定义消息模板应改用 cometchat-android-v5-customization。

架构:扩展分为两类。注册器类(如 PollsExtension、StickerExtension)继承 ExtensionsDataSource,通过 setExtensions(...) 传入以启用内置扩展;装饰器类(如 PollsExtensionDecorator)继承 DataSourceDecorator,是运行时包装 DataSource 链的装饰器,由 Kit 内部创建,不直接构造。

内置扩展:Polls(投票)、Stickers(贴纸)、Collaborative Document(协作文档)、Collaborative Whiteboard(协作白板)、Smart Replies(AI 回复建议)、Message Translation(消息翻译)、Text Moderation(文本审核)、Thumbnail Generation(缩略图生成),各自对应 com.cometchat.chatuikit.extensions 下的包。

启用与禁用:扩展默认启用。通过 UIKitSettingsBuilder 的 setExtensions(...) 传入自定义列表,列表元素必须是注册器而非装饰器,未加入的扩展即被禁用。

自定义扩展:需要两个类——继承 ExtensionsDataSource 的注册器(实现 getExtensionId() 与 enable(),enable() 内调用 ChatConfigurator.enable(...) 创建装饰器)和继承 DataSourceDecorator 的装饰器(重写逐消息行为)。注册器加入 setExtensions(...)。

限制:ChatConfigurator.enable() 必须在 CometChatUIKit.init() 成功后调用;客户端注册后仍需在后端启用对应扩展,可用 cometchat apply-feature <id> --app-id <X>;Giphy、Stipop、Tenor、Chatwoot、Intercom 等需要第三方 API Key 的扩展须在仪表盘手动配置。