Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

WhatsApp InstantMessaging

WhatsApp 即时通讯服务——Cloud API System User Token Bearer 鉴权。

Last updated

基于 WhatsApp Business Cloud API 实现,采用 System User Token Bearer 鉴权。

包信息

  • NuGet 包:Bitzsoft.Integrations.InstantMessaging.WhatsApp
  • 接口:IInstantMessagingService
  • 鉴权:Cloud API Bearer(System User Token)
  • Provider ID:whatsapp

配置

字段类型必填默认值说明
AccessTokenstringSystem User Token(Bearer 鉴权凭据)
PhoneNumberIdstring已注册的电话号码 ID
BaseUrlstringhttps://graph.facebook.com/v18.0Graph API 基地址(不含 phone_number_id)
HttpClientNamestringInstantMessagingWhatsApp业务 HttpClient 命名
{
"InstantMessaging": {
"WhatsApp": {
"AccessToken": "your-access-token",
"PhoneNumberId": "your-phone-number-id"
}
}
}

注册

// 方式一:IConfiguration(默认读取 "InstantMessaging:WhatsApp" 配置节)
services.AddWhatsAppInstantMessaging(configuration);
// 方式二:委托配置
services.AddWhatsAppInstantMessaging(options =>
{
options.AccessToken = "your-access-token";
options.PhoneNumberId = "your-phone-number-id";
});

使用示例

// 发送文本消息
var result = await im.SendTextMessageAsync(new SendTextMessageRequest
{
Channel = "1234567890",
Text = "Your order has been shipped!"
});
// 更新消息
await im.UpdateMessageAsync("msg-id", "Updated content");

鉴权机制

  • 每个请求通过 Authorization: Bearer {AccessToken} 头携带 System User Token。
  • phone_number_id 在运行时拼入请求路径(/{PhoneNumberId}/messages)。

已知限制

WhatsApp Cloud API 无频道列表查询和成员邀请能力(与 Slack/Discord 的频道模型不同)。ListChannelsAsync/CreateChannelAsync/InviteMemberAsync 的语义按 WhatsApp 实际能力实现或受限。

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%