layotto icon indicating copy to clipboard operation
layotto copied to clipboard

proposal: SMS notify API [SaaS API]

Open kevinten10 opened this issue 3 years ago • 1 comments

Hi, This is SMS notify API proposal.

What would you like to be added:

saas api: SMS notify api

Why is this needed:

https://github.com/mosn/layotto/issues/712

Support situation:

SMS Docs
Aliyun SMS https://help.aliyun.com/document_detail/419273.htm?spm=a2c4g.11186623.0.0.3437bb6eHzhqjY
AWS Pinpoint https://docs.aws.amazon.com/zh_cn/pinpoint/latest/developerguide/send-messages-sms.html
Tencent SMS https://cloud.tencent.com/document/api/382/55981

API spec:

// Saas API
// Send the message to SMS.
rpc SendSms(SendSmsRequest) returns (SendSmsResponse) {}

------

// SendSmsRequest is the message send to sms.
message SendSmsRequest {

  // The invoke Id.
  string id = 1;

  // The saas service name, like 'aliyun.sms'/'aws.pinpoint'/'...'
  string saas_name = 2;

  // The unique identifier for the SMS application.
  string application_id = 3;

  // The SMS sender tag.
  string sender_id = 4;

  // The SMS receive phone numbers.
  repeated string phone_numbers = 5;

  // The SMS message type, like 'text'/'voice'/'...'
  string message_type = 6;

  // The SMS message data.
  bytes message_data = 7;

  // The metadata which will be sent to SMS components.
  map<string, string> metadata = 8;
}

message SendSmsResponse {
  // The saas requestId.
  string request_id = 1;

  // The data response from SMS service.
  bytes data = 2;

  // The metadata returned from SMS service.
  map<string, string> metadata = 3;
}

字段设计考虑:

1. SMS原生API非常复杂,难取交集

aliyun/aws/tencent/...,在原生API设计上都有很多自己独特的请求参数,这取决于云SMS自身的一些设计。

例如:

  • 消息模板ID:有的SMS具有模板,有的SMS不需要模板即可发送。
  • messageType:每种SMS,可能有自己的type类型,无法对齐

2. SMS具有弱移植性

一个公司,如果SMS的目的是做通知(数量较少,对内),而不是大规模的对客营销/通知(这种场景应该自行部署一个服务,而不是使用runtime提供的saas能力),那么大概率也只会使用一种SMS工具(申请、维护、成本、管理、地域等各方面)。

所以本身SMS代码就不需要很强的可移植性,那么对于一些特有的字段,可以接受放在metadata中。

3. Runtime API取核心字段,其他字段放metadata

尽可能取多种SMS都有的一些概念,将这些字段放在API中,其他字段放metadata。

对于一次SMS发送,有几个字段是必需的:

  1. application_id:SMS属于比较重量级的资源,同时可能具备一定的社会影响,所以资源监管比较严格。往往需要提前审核SMS模板等,会赋予一个application_id,作为该模板的标识。
  2. sender_id:sms场景有时可以传入senderId
  3. phone_numbers:接收手机号列表
  4. message_type:SMS多媒体支持(语音/彩信等),使用该字段标识消息类型
  5. message_data:对应message_type的消息体

以及,设计两个基础字段:

  1. id:用于进行一定的标识,从而可以实现基于id获取配置的功能。往往SMS的配置相对静态,可以通过id获取SMS的相关配置,减少在metadata中的字段
  2. saas_name:多SMS场景时使用,保留这样的可拓展性。当用到该场景时,由于不同SMS的发送参数有巨大差异,如果在代码中传递metadata等字段,则可能无法移植,这时候就需要上述的 id 功能。

kevinten10 avatar Jul 11 '22 13:07 kevinten10

This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue or help wanted) or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 11 '22 03:08 github-actions[bot]

@kevinten10 hi, 我基于这个proposal 提交了 pr https://github.com/mosn/layotto/pull/814 可以帮忙看下哈~ 我做了一些修改,把“基于模板发短信” 和 “不基于模板、直接发短信” 拆成了两个方法,目前 PR 只提交了前者,后者后面再加

seeflood avatar Oct 19 '22 06:10 seeflood