快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-intercom`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/intercom/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-intercom` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-intercombunx cap sync导入
“导入”章节import { CapgoIntercom } from '@capgo/capacitor-intercom';快速入门
章节标题为“快速入门”在以下代码中配置 Intercom capacitor.config 或调用 loadWithKeys() 在调用以下 API 之前。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.loadWithKeys({ appId: 'your-app-id', apiKeyIOS: 'ios-api-key', apiKeyAndroid: 'android-api-key',});await CapgoIntercom.registerIdentifiedUser({ userId: '42', email: 'user@example.com' });await CapgoIntercom.displayMessenger();示例:帮助中心文章
标题为“示例:帮助中心文章”的章节await CapgoIntercom.displayArticle({ articleId: '12345' });示例:未读角标
标题为“示例:未读角标”的章节await CapgoIntercom.addListener('unreadCountDidChange', ({ count }) => { setBadge(count);});常见坑点
章节标题为“常见陷阱”- 密钥: 调用
loadWithKeys()或在配置其他 API 之前设置 Intercom 密钥。 - 退出登录: 调用
logout()当应用用户登出时,以避免身份泄露。 - Web 端:Messenger API 仅支持原生。
API 概览
章节标题:“API 概览”loadWithKeys
标题为 “loadWithKeys” 的章节在运行时使用 API 密钥初始化 Intercom。 如果您不希望将密钥配置在 capacitor.config 中,请使用此方法。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.loadWithKeys({ appId: 'app-id-123', apiKeyIOS: 'api-key-ios', apiKeyAndroid: 'api-key-android',});registerIdentifiedUser
标题为 “registerIdentifiedUser” 的章节向 Intercom 注册已知用户。 必须提供 userId 或 email 中的至少一个。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.registerIdentifiedUser({ userId: 'user-id-123', email: 'user@example.com',});registerUnidentifiedUser
标题为 “registerUnidentifiedUser” 的章节在 Intercom 中注册匿名用户。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.registerUnidentifiedUser();updateUser
标题为 “updateUser” 的章节更新 Intercom 中的用户属性。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.updateUser({ userId: 'user-id-123' });logout
标题为“退出登录”的部分让用户退出 Intercom 登录。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.logout();logEvent
标题为“logEvent”的章节在 Intercom 中记录自定义事件。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.logEvent({ name: 'example' });displayMessenger
标题为 “displayMessenger” 的章节打开 Intercom 消息窗口。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayMessenger();displayMessageComposer
标题为 “displayMessageComposer” 的章节打开消息编辑器,并预填消息内容。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayMessageComposer({ message: 'Hello from Capacitor' });displayHelpCenter
标题为 “displayHelpCenter” 的章节打开 Intercom 帮助中心。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayHelpCenter();hideMessenger
标题为 “hideMessenger” 的章节隐藏 Intercom 消息窗口。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.hideMessenger();displayLauncher
标题为 “displayLauncher” 的章节显示 Intercom 启动按钮。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayLauncher();hideLauncher
标题为 “hideLauncher” 的章节隐藏 Intercom 启动按钮。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.hideLauncher();displayInAppMessages
标题为 “displayInAppMessages” 的章节启用来自 Intercom 的应用内消息。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayInAppMessages();hideInAppMessages
标题为 “hideInAppMessages” 的章节禁用来自 Intercom 的应用内消息。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.hideInAppMessages();displayCarousel
标题为 “displayCarousel” 的章节显示特定的 Intercom 轮播。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayCarousel({ carouselId: 'carousel-id-123' });displayArticle
标题为 “displayArticle” 的章节显示特定的 Intercom 文章。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displayArticle({ articleId: 'article-id-123' });displaySurvey
“displaySurvey” 部分显示特定的 Intercom 调查。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.displaySurvey({ surveyId: 'survey-id-123' });setUserHash
“setUserHash” 部分设置用于身份验证的 HMAC。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.setUserHash({ hmac: 'hmac' });setUserJwt
“setUserJwt” 部分设置用于安全 Messenger 身份验证的 JWT。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.setUserJwt({ jwt: 'jwt' });setBottomPadding
“setBottomPadding” 部分设置 Intercom Messenger UI 的底部内边距。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.setBottomPadding({ value: 1 });sendPushTokenToIntercom
“sendPushTokenToIntercom” 章节向 Intercom 发送推送通知 token。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.sendPushTokenToIntercom({ value: 'value' });receivePush
“receivePush” 章节处理收到的 Intercom 推送通知。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
await CapgoIntercom.receivePush({});getUnreadConversationCount
“getUnreadConversationCount” 章节获取当前用户的未读会话数。
import { CapgoIntercom } from '@capgo/capacitor-intercom';
const result = await CapgoIntercom.getUnreadConversationCount();console.log(result);类型参考
“类型参考” 章节IntercomLoadOptions
“IntercomLoadOptions” 章节export interface IntercomLoadOptions { appId?: string; apiKeyIOS?: string; apiKeyAndroid?: string;}IntercomIdentifiedUserOptions
标题为“IntercomIdentifiedUserOptions”的章节export interface IntercomIdentifiedUserOptions { userId?: string; email?: string;}IntercomUserUpdateOptions
标题为“IntercomUserUpdateOptions”的章节export interface IntercomUserUpdateOptions { userId?: string; email?: string; name?: string; phone?: string; languageOverride?: string; customAttributes?: { [key: string]: any }; companies?: IntercomCompany[];}IntercomLogEventOptions
标题为“IntercomLogEventOptions”的章节export interface IntercomLogEventOptions { name: string; data?: { [key: string]: any };}IntercomMessageComposerOptions
标题为“IntercomMessageComposerOptions”的章节export interface IntercomMessageComposerOptions { message: string;}IntercomCarouselOptions
标题为“IntercomCarouselOptions”的章节export interface IntercomCarouselOptions { carouselId: string;}IntercomArticleOptions
标题为“IntercomArticleOptions”的章节export interface IntercomArticleOptions { articleId: string;}IntercomSurveyOptions
“IntercomSurveyOptions” 章节export interface IntercomSurveyOptions { surveyId: string;}IntercomUserHashOptions
“IntercomUserHashOptions” 章节export interface IntercomUserHashOptions { hmac: string;}IntercomUserJwtOptions
“IntercomUserJwtOptions” 章节export interface IntercomUserJwtOptions { jwt: string;}IntercomBottomPaddingOptions
“IntercomBottomPaddingOptions” 章节export interface IntercomBottomPaddingOptions { value: number;}IntercomPushTokenOptions
“IntercomPushTokenOptions” 章节export interface IntercomPushTokenOptions { value: string;}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-intercom 用于“使用 @capgo/capacitor-intercom”中的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。