跳到正文
DEV Community· Built By AI Lab·· 2 天前AI 評分37

我的應用程式為何不會自行發送 WhatsApp 訊息

Why my app never sends a WhatsApp message by itself

AI 導讀

這款應用程式不會自行發送 WhatsApp 訊息,而是由店主開啟連結,在 WhatsApp 檢視預填文字後按下發送。伺服器會核對客戶同意、退訂狀態、排除名單及優惠和時段是否仍有效,並限制可準備訊息的時間為羅馬時間 9:00 至 21:00,每日上限預設為 20 則。程式亦以條件更新防止重複發送,並設有測試,確保檔案不含向訊息服務 API 發送網絡請求的程式碼。

正文

Built By AI Lab

When a customer cancels, the app prepares a message and a link. The salon owner opens the link, WhatsApp shows the chat with the text already in it, and the owner presses Send. The app has no way to send anything on its own, and that was a design decision before it was a feature.

The rules sit on the server, where the browser cannot argue with them. Every time the owner presses the button, the server loads the offer, the customer and the slot again from the database and checks them. The customer must have agreed to receive messages, and the text and the channel of that agreement are stored. The customer must not have said STOP. The number must not be on the exclusion list. The offer must still be waiting and the slot still free. The phone number and the text come from the database. Whatever the form sends is ignored.

Time and volume have limits as well. Messages can be prepared between 9:00 and 21:00 in Rome. A daily cap applies, set to 20 by default.

Every message ends with a fixed line that carries the salon's name and tells the customer how to stop receiving messages. The owner can edit the text before sending. If the edit removes that line, the server puts it back.

A double click used to be a problem. Two quick requests could pass the "is it still waiting?" check before either one updated the offer, and the owner would have two links for one customer. Now the update itself is conditional, and only the request that really changed the status goes on. The second one is stopped.

A test in the project also fails if any file contains a network request to a messaging provider's API. Automatic sending is excluded from the code and not just switched off in a setting, so a wrong value in a settings page cannot start it.

An owner can move faster with a one-click bulk send. I decided the app would never offer one, because a message sent in the wrong minute to the wrong person cannot be taken back.


Disclosure: drafted with a local AI model, then reviewed and approved by me. Originally published at https://bbal-blog.kairo-app.workers.dev/why-my-app-never-sends-a-whatsapp-message-by-itself/

來源:DEV Community · dev.to