jerrychen428 commited on
Commit
8bb2b41
·
verified ·
1 Parent(s): 04eb0f6

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -117
app.py DELETED
@@ -1,117 +0,0 @@
1
- import streamlit as st
2
- from twilio.rest import Client
3
- import os
4
-
5
- # 設定頁面標題
6
- st.title("📱 SMS 發送工具")
7
- st.write("使用 Twilio 發送 SMS 訊息")
8
-
9
- # 側邊欄設定 Twilio 憑證
10
- st.sidebar.header("🔧 Twilio 設定")
11
- account_sid = st.sidebar.text_input(
12
- "Account SID",
13
- value="ACd7f840e0ea441d49885b4ab7a8828c46",
14
- type="password"
15
- )
16
- auth_token = st.sidebar.text_input(
17
- "Auth Token",
18
- value="b3f7af530024eb7bf68e3576f5fe3ad7",
19
- type="password"
20
- )
21
-
22
- # 主要介面
23
- st.header("📝 發送訊息")
24
-
25
- # 發送者號碼(Twilio 虛擬號碼)
26
- from_number = st.text_input(
27
- "發送者號碼 (Twilio 虛擬號碼)",
28
- value="+17623355728",
29
- help="請輸入你的 Twilio 虛擬手機號碼"
30
- )
31
-
32
- # 接收者號碼
33
- to_number = st.text_input(
34
- "接收者號碼",
35
- value="+886919017732",
36
- help="請輸入要發送的手機號碼(包含國碼)"
37
- )
38
-
39
- # 訊息內容
40
- message_body = st.text_area(
41
- "訊息內容",
42
- value="20250831 測試",
43
- height=100,
44
- help="請輸入要發送的訊息內容"
45
- )
46
-
47
- # 預覽訊息
48
- if message_body:
49
- st.subheader("📋 訊息預覽")
50
- st.info(f"**發送至:** {to_number}\n\n**訊息內容:**\n{message_body}")
51
-
52
- # 發送按鈕
53
- col1, col2, col3 = st.columns([1, 2, 1])
54
- with col2:
55
- send_button = st.button("🚀 發送 SMS", type="primary", use_container_width=True)
56
-
57
- # 發送邏輯
58
- if send_button:
59
- # 驗證輸入
60
- if not account_sid or not auth_token:
61
- st.error("❌ 請在側邊欄設定 Twilio Account SID 和 Auth Token")
62
- elif not from_number or not to_number:
63
- st.error("❌ 請輸入發送者和接收者號碼")
64
- elif not message_body.strip():
65
- st.error("❌ 請輸入訊息內容")
66
- else:
67
- try:
68
- # 顯示發送中狀態
69
- with st.spinner("📤 正在發送訊息..."):
70
- # 建立 Twilio 客戶端
71
- client = Client(account_sid, auth_token)
72
-
73
- # 發送訊息
74
- message = client.messages.create(
75
- from_=from_number,
76
- to=to_number,
77
- body=message_body
78
- )
79
-
80
- # 顯示成功訊息
81
- st.success("✅ 訊息發送成功!")
82
- st.balloons()
83
-
84
- # 顯示訊息詳情
85
- with st.expander("📊 發送詳情", expanded=True):
86
- st.write(f"**訊息 SID:** {message.sid}")
87
- st.write(f"**狀態:** {message.status}")
88
- st.write(f"**發送時間:** {message.date_created}")
89
-
90
- except Exception as e:
91
- st.error(f"❌ 發送失敗:{str(e)}")
92
- st.write("請檢查:")
93
- st.write("• Twilio 憑證是否正確")
94
- st.write("• 手機號碼格式是否正確(需包含國碼)")
95
- st.write("• Twilio 帳戶餘額是否足夠")
96
- st.write("• 接收號碼是否已驗證(試用帳戶限制)")
97
-
98
- # 使用說明
99
- with st.expander("📖 使用說明"):
100
- st.write("""
101
- ### 設定步驟:
102
- 1. 在側邊欄輸入你的 Twilio Account SID 和 Auth Token
103
- 2. 確認發送者號碼(你的 Twilio 虛擬號碼)
104
- 3. 輸入接收者的手機號碼(需包含國碼,如 +886 開頭)
105
- 4. 輸入要發送的訊息內容
106
- 5. 點擊「發送 SMS」按鈕
107
-
108
- ### 注意事項:
109
- - 手機號碼必須包含國碼(例如:台灣 +886,美國 +1)
110
- - 試用帳戶只能發送到已驗證的號碼
111
- - 確保 Twilio 帳戶有足夠餘額
112
- - 訊息長度限制為 1600 字元
113
- """)
114
-
115
- # 頁腳
116
- st.markdown("---")
117
- st.markdown("*使用 Streamlit 和 Twilio API 建構*")