Capacitor Intercom

Intercom Capacitor插件

将Intercom的实时聊天、帮助中心和支持工作流程集成到您的Capacitor应用中

安装

bun add @capgo/capacitor-intercom bunx cap sync
npm、pnpm或yarn
  • npm install @capgo/capacitor-intercom
  • pnpm add @capgo/capacitor-intercom
  • yarn add @capgo/capacitor-intercom

指南

如何在 Capacitor 中使用 Intercom

在设备上测试

下载 Capgo 应用程序,然后扫描二维码 code

Intercom 插件预览二维码 code

使用 @capgo/capacitor-intercom

Intercom Capacitor 插件

安装

bun add @capgo/capacitor-intercom
bunx cap sync

bunx cap sync 将插件的本机 code 复制到您的本机项目中。每次升级插件后,请再次运行。

导入

import { CapgoIntercom } from '@capgo/capacitor-intercom';

API 简介

方法 描述
loadWithKeys 在运行时使用 API 键初始化 Intercom。使用此选项如果您不想在 capacitor.config 中配置键。
registerIdentifiedUser 注册已知用户与 Intercom。至少需要提供一个 userId 或 email。
registerUnidentifiedUser 注册匿名用户与 Intercom。
updateUser 在 Intercom 中更新用户属性。
logout 从 Intercom 登出用户。
logEvent 在 Intercom 中记录自定义事件。
displayMessenger 打开 Intercom 消息传递器。
displayMessageComposer 打开带有预填写消息的消息编辑器。
displayHelpCenter 打开 Intercom 帮助中心。
hideMessenger 隐藏 Intercom 消息传递器。
displayLauncher 显示 Intercom 启动按钮。
hideLauncher 隐藏 Intercom 启动按钮。
displayInAppMessages 在应用内显示 Intercom 的消息。
hideInAppMessages 关闭 Intercom 的应用内消息。
displayCarousel 显示特定的 Intercom 轮播。
displayArticle 显示特定的 Intercom 文章。
displaySurvey 显示特定的 Intercom 问卷。
setUserHash 设置身份验证的 HMAC 值。
setUserJwt 设置安全的消息者认证 JWT 值。
setBottomPadding 设置 Intercom 消息者 UI 的底部间距。
sendPushTokenToIntercom 将推送通知令牌发送到 Intercom。
receivePush 处理从 Intercom 接收的推送通知。
getUnreadConversationCount 获取当前用户的未读对话数。

示例

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()

在Intercom中注册已知用户。至少需要提供一个userId或email。

import { CapgoIntercom } from '@capgo/capacitor-intercom';

await CapgoIntercom.registerIdentifiedUser({
  userId: 'user-id-123',
  email: 'user@example.com',
});

registerUnidentifiedUser()

在Intercom中注册匿名用户。

import { CapgoIntercom } from '@capgo/capacitor-intercom';

await CapgoIntercom.registerUnidentifiedUser();

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()

在Intercom中记录自定义事件。

import { CapgoIntercom } from '@capgo/capacitor-intercom';

await CapgoIntercom.logEvent({ name: 'example' });

上表列出了23个核心方法。监听器和版本辅助函数,以及每个方法的完整契约,均在__CAPGO_KEEP_0__仓库中文档化。 GitHub 仓库.

返回一个句柄。调用

addListener 当屏幕卸载时,或者 handle.remove() 清除所有监听器。 CapgoIntercom.removeAllListeners() __CAPGO_KEEP_0__仓库

全参考

继续使用@capgo/capacitor-intercom

使用 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-intercom 使用@capgo/capacitor-intercom @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-intercom 查看 @capgo/capacitor-intercom 的实现细节 为@capgo/capacitor-intercom的实现细节 查看开始的实现细节 全参考 Capgo 插件目录 为 Capgo 产品工作流程在 Capgo 插件目录中 Capacitor 由 Capgo 提供的插件 为 Capacitor 插件由 Capgo 的实现细节 添加或更新插件 为添加或更新插件的实现细节

常见问题

Intercom插件FAQ

如何在Capacitor应用中安装Intercom插件?

运行"bun add @capgo/capacitor-intercom"(或"npm install @capgo/capacitor-intercom"),然后运行"bunx cap sync",使iOS和Android项目捕获native code。从"@capgo/capacitor-intercom"中导入它,然后在code应用中使用。

是否@capgo/capacitor-intercom与React、Vue和Angular兼容?

是。Intercom是一个Capacitor包,因此它与任何在Capacitor中运行的Web框架一起工作,包括Ionic、React、Vue、Angular、Svelte和普通JavaScript。

哪个Capacitor版本支持@capgo/capacitor-intercom?

Capgo插件遵循Capacitor的主要版本:使用与Capacitor主要版本匹配的插件主要版本(例如插件v8与Capacitor 8)。在GitHub README中列出的兼容性表格列出了维护的版本。

是否@capgo/capacitor-intercom 免费且开源?

是。源码code在GitHub上公开,https://github.com/Cap-go/capacitor-intercom/,并且可以从npm免费安装。bug报告和pull请求都欢迎。

是否可以在App Store不经过审核更新使用code的Intercom?

安装或升级插件会改变原生code,因此需要重新构建App Store。之后,使用Capgo实时更新的JavaScript、HTML和CSS可以立即部署。

不必等待应用程序审查就可以将Intercom更新

一旦插件添加到您的商店中,Capgo即可实时更新JavaScript、HTML和CSS更改

开始使用Capgo