# TV 速報串接 Sendinblue 自動化使用說明
機制設計請參考 [Trello 卡片](https://trello.com/c/QodsUjrf),大致上是提供一個 API 每次收到一則速報時就呼叫一次,系統會根據存放的設定決定要不要發、要怎麼發。並提供一設定頁面可以調整。
## Create Message
對以下路徑下 HTTP POST 在 payload 中帶 JSON
```
POST https://ems.freetv-app.com/sib/messages?key=<key>
api-key: <api-key>
Content-Type: application/json
{
"name": "<string: 顯示在 sendinblue 後台的 Campaign 名稱>",
"params": {
"subject": "<string: 新聞標題>",
"source": "<string: 新閱來源>",
"content": "<string: ref 內新聞內文抓前 100 字再加 …>",
"thumbnail": "<string: 圖片網址>",
"url": "https://web.freetv-app.com/jp/email/open_app"
}
}
```
其中
- `<key>` 用來指定要使用哪組設定,目前有
- `tv-jp-breaking-news-android`
- `tv-jp-breaking-news-ios`
- `<api-key>` 為固定字串,請找後端要
### 範例
```
POST https://ems.freetv-app.com/sib/messages?key=tv-jp-breaking-news-android
api-key: <api-key>
Content-Type: application/json
{
"name": "速報測試 20220804-1",
"params": {
"subject": "山形・新潟などで記録的豪雨 最上川なども複数箇所で氾濫 被害情報まとめ",
"source": "ニュースダイジェスト",
"content": "(ref 內新聞內文抓前 100 字再加 …)",
"thumbnail": "https://newsdigest.jp/media/articles/%E6%96%87%E5%AD%97%E3%81%AA%E3%81%97%E9%9B%B7%E9%9B%A8_jdJa9AA.png",
"url": "https://web.freetv-app.com/jp/email/open_app?utm_source=sendinblue&utm_campaign=breaking&utm_medium=email&comment=一個手機版點了會開 app, 桌面版點了會開商店的網址"
}
}
```
## Config
到 [白底設編輯器](https://internal-web.freetv-app.com/config-editor) 裡選擇 **emsSibMessageConfig** 以後找到對應的 Key 編輯
### 範例
```
{
"key": "tv-jp-breaking-news-android",
"createCampaignOnly": true,
"quota": 1,
"templateId": 151,
"recipients": {
"exclusionListIds": [],
"listIds": [
6
]
},
"tag": "速報",
"excludeMessagesWithTexts": [
"新型コロナ"
],
"apiKeySuffix": "-hSMxIqcrGO1JntQm"
}
```
- `key`: 設定檔 id, 發訊息時指定用
- `createCampaignOnly`: 設定為 `true` 時只會建立 Campaign 但不會自動發送
- `quota`: 目前還會自動發幾封以後才停止,停止後設重新設定為大於零的值才會繼續發
- `templateId`: 使用的 templateId
- `recipients.listIds`: 要發送的 `listId` 清單
- `recipients.exclusionListIds`: 要排除的 `listId` 清單
- `tag`: 指定 Sendinbe Campaign 的 tag
- `excludeMessagesWithTexts`: 若收到的資料裡 `source` 或 `content` 包含指定的字串則不會發
- `apiKeySuffix`: 工程端檢查資料用
## Operation
設定資料存放在 DynamoDB 的 `EmsSibMessageConfig` 表格中,其中 `{ key:"_index" }` 的為特殊項目,用以決定在白底列表顯示的項目有哪些。
提供給前端的 `api-key` 的值為 Sendinblue 的 API Key 再經過加密後的結果,請參考 `emb-public-service` 中 `crypto.service.spec.ts` 測試檔執行產生。