import streamlit as st from twilio.rest import Client import os # 從 Hugging Face Spaces 的環境變數讀取帳號密碼 account_sid = os.environ.get("accountSid") auth_token = os.environ.get("authToken") twilio_phone_number = os.environ.get("from_") # Streamlit 介面 st.title("Twilio 簡訊發送器 📱") to_phone = st.text_input("輸入要寄送的手機號碼(此功能已無效)只能寄給Peter) (例: +886910256541)") message_body = st.text_area("輸入要發送的訊息內容:", value="你可能忘了更改要傳送的簡訊內容喔") if st.button("發送簡訊"): if not account_sid or not auth_token or not twilio_phone_number: st.error("找不到 Twilio 設定,請設定好環境變數!") elif not to_phone or not message_body: st.warning("請填寫完整的手機號碼和訊息內容。") else: try: client = Client(account_sid, auth_token) message = client.messages.create( from_=twilio_phone_number, to=to_phone, body=message_body ) st.success(f"簡訊已成功送出!訊息 SID:{message.sid}") except Exception as e: st.error(f"發送失敗:{str(e)}")