-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_mms.exs
More file actions
67 lines (52 loc) · 1.95 KB
/
send_mms.exs
File metadata and controls
67 lines (52 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env elixir
# MMS (멀티미디어 메시지) 발송 예제
# Storage API를 사용하여 이미지 업로드 후 MMS 발송
# 실행: elixir examples/send_mms.exs
Mix.install([
{:solapi, path: Path.join(__DIR__, "..")}
])
api_key = System.get_env("SOLAPI_API_KEY") || raise "SOLAPI_API_KEY 환경변수를 설정하세요"
api_secret = System.get_env("SOLAPI_API_SECRET") || raise "SOLAPI_API_SECRET 환경변수를 설정하세요"
client = Solapi.client(api_key: api_key, api_secret: api_secret)
# 이미지 파일 경로
image_path = Path.join(__DIR__, "example.jpg")
IO.puts("""
MMS 발송 예제 (Storage 연동)
1. 이미지 업로드: #{image_path}
2. fileId 획득 후 MMS 발송
""")
# Step 1: 이미지 업로드
IO.puts("Step 1: 이미지 업로드 중...")
case Solapi.upload_file(client, image_path, "MMS") do
{:ok, upload_response} ->
file_id = upload_response["fileId"]
IO.puts("이미지 업로드 성공!")
IO.puts("fileId: #{file_id}")
IO.inspect(upload_response, label: "업로드 응답", pretty: true)
# Step 2: MMS 발송
IO.puts("\nStep 2: MMS 발송 중...")
message = %{
# 수신번호 (실제 번호로 변경)
to: "01012345678",
# 발신번호 (실제 등록된 발신번호로 변경)
from: "01000000000",
# MMS 지정
type: "MMS",
# 제목 (선택)
subject: "이미지 메시지",
text: "MMS 테스트 메시지입니다. 이미지가 첨부되어 발송됩니다.",
# 업로드된 이미지 ID 사용
image_id: file_id
}
case Solapi.send(client, message) do
{:ok, response} ->
IO.puts("MMS 발송 성공!")
IO.inspect(response, label: "발송 응답", pretty: true)
{:error, error} ->
IO.puts("MMS 발송 실패!")
IO.inspect(error, label: "에러", pretty: true)
end
{:error, error} ->
IO.puts("이미지 업로드 실패!")
IO.inspect(error, label: "에러", pretty: true)
end