iT邦幫忙

2025 iThome 鐵人賽

DAY 27
0
生成式 AI

打造自己的 AI 新聞小編:每天自動抓新聞、摘要、推送到 LINE!系列 第 27

【Day 26】主題選單功能(四)— 判斷是否傳新聞

  • 分享至 

  • xImage
  •  

今天要增加的三個 If 節點是用來判斷是否傳送新聞,而傳送新聞的部分早在我們做關鍵字搜索的功能時,就已經設置過了,所以接下來就只需要做一些小小更改,這部分架構和之前是一樣的,只差在一些小地方。

是否傳送新聞

在昨天新增的三個 If 節點的 false 分支各別新增一個 If 節點,如果沒有超過上限就往下走,到是否判斷傳送新聞的節點。

https://ithelp.ithome.com.tw/upload/images/20250929/20178067kO6T0T9Ump.png

國際新聞

https://ithelp.ithome.com.tw/upload/images/20250929/20178067iFgjauzNUP.png

科技新聞

https://ithelp.ithome.com.tw/upload/images/20250929/201780679xtZlL5DgA.png

娛樂新聞

https://ithelp.ithome.com.tw/upload/images/20250929/20178067niyEdeSNHy.png

true : 往下到傳新聞的節點;false : 不用接其他節點。

傳送新聞

把之前做關鍵字搜索的這段節點複製加到現在的選單功能流程中,接在剛剛新增的三個 If 節點 true 分支後面。

https://ithelp.ithome.com.tw/upload/images/20250929/20178067ebujB8af6c.png

判斷新聞主題

Code(RSS URL) 節點的程式碼更改成:

const lastTopicCN = $input.first().json.lastTopicCN; 
let rssUrl;

switch (lastTopicCN) {
  case "國際":
    rssUrl = "https://feeds.feedburner.com/rsscna/intworld";
    break;
  case "科技":
    rssUrl = "https://feeds.feedburner.com/rsscna/technology";
    break;
  case "娛樂":
    rssUrl = "https://feeds.feedburner.com/rsscna/stars";
    break;
}

return {
  json: { rssUrl, userId: $input.first().json.userId, lastTopicCN: $input.first().json.lastTopicCN }
};

這段程式碼和之前不同的地方在於抓的新聞主題。

抓新聞網址

RSS Read 節點的內容不變,一樣用來抓新聞網址。
https://ithelp.ithome.com.tw/upload/images/20250929/20178067mqQP0nlZKh.png

下篇預告

明天(Day 27)要進入到「每次點擊就抓三則新聞」的部分了~


上一篇
【Day 25】主題選單功能(三)— 判斷條件搞清楚執行流程
下一篇
【Day 27】主題選單功能(五)— 打造不重複新聞推播系統
系列文
打造自己的 AI 新聞小編:每天自動抓新聞、摘要、推送到 LINE!29
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言