-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_multiple.exs
More file actions
68 lines (55 loc) · 1.83 KB
/
send_multiple.exs
File metadata and controls
68 lines (55 loc) · 1.83 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
68
#!/usr/bin/env elixir
# 다중 메시지 발송 예제
# 실행: elixir examples/send_multiple.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)
# 여러 수신자에게 동시 발송
# 리스트로 메시지를 전달하면 한 번의 API 호출로 다중 발송됩니다.
messages = [
%{
to: "01012345678",
from: "0212345678",
text: "첫 번째 수신자에게 보내는 메시지"
},
%{
to: "01087654321",
from: "0212345678",
text: "두 번째 수신자에게 보내는 메시지"
},
%{
to: "01011112222",
from: "0212345678",
text: "세 번째 수신자에게 보내는 메시지"
}
]
IO.puts("#{length(messages)}건의 메시지 발송 중...")
case Solapi.send(client, messages) do
{:ok, response} ->
IO.puts("다중 발송 완료!")
IO.inspect(response, label: "응답", pretty: true)
{:error, error} ->
IO.puts("발송 실패!")
IO.inspect(error, label: "에러", pretty: true)
end
# 동적으로 메시지 리스트 생성 예제
IO.puts("\n--- 동적 메시지 생성 예제 ---\n")
recipients = ["01012345678", "01087654321", "01099998888"]
base_message = "안녕하세요, 이벤트 안내입니다."
dynamic_messages =
recipients
|> Enum.with_index(1)
|> Enum.map(fn {phone, index} ->
%{
to: phone,
from: "0212345678",
text: "#{base_message} (#{index}/#{length(recipients)})"
}
end)
IO.puts("동적 생성된 메시지 리스트:")
IO.inspect(dynamic_messages, pretty: true)
# 실제 발송하려면 아래 주석 해제
# Solapi.send(client, dynamic_messages)