Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 9cfef10

Browse files
authored
Merge pull request #10 from coolsms/feature-message
Feature message
2 parents c8497d2 + 915580b commit 9cfef10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1446
-418
lines changed

LICENSE

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Coolsms Python SDK
2+
3+
Send Message & Message Management using Python and REST API.
4+
5+
## Version
6+
7+
v2.0
8+
9+
## License
10+
11+
GPL v2 License
12+
13+
## Installation
14+
15+
- Package install url ( source code & examples ) : http://www.coolsms.co.kr/download/545387
16+
17+
- Github : https://github.com/coolsms/python-sdk
18+
19+
## Usage
20+
21+
### Send Message
22+
```python
23+
from sdk.api.message import Message
24+
from sdk.exceptions import CoolsmsException
25+
26+
# set api key, api secret
27+
api_key = "#ENTER_YOUR_OWN#"
28+
api_secret = "#ENTER_YOUR_OWN#"
29+
30+
## 4 params(to, from, type, text) are mandatory. must be filled
31+
params = dict()
32+
params['type'] = 'sms' # Message type ( sms, lms, mms, ata )
33+
params['to'] = '01000000000' # Recipients Number '01000000000,01000000001'
34+
params['from'] = '01000000000' # Sender number
35+
params['text'] = 'Test Message' # Message
36+
37+
cool = Message(api_key, api_secret)
38+
try:
39+
response = cool.send(params)
40+
print("Success Count : %s" % response['success_count'])
41+
print("Error Count : %s" % response['error_count'])
42+
print("Group ID : %s" % response['group_id'])
43+
44+
if "error_list" in response:
45+
print("Error List : %s" % response['error_list'])
46+
47+
except CoolsmsException as e:
48+
print("Error Code : %s" % e.code)
49+
print("Error Message : %s" % e.msg)
50+
```
51+
52+
### Message History
53+
```python
54+
from sdk.api.message import Message
55+
from sdk.exceptions import CoolsmsException
56+
57+
# set api key, api secret
58+
api_key = "#ENTER_YOUR_OWN#"
59+
api_secret = "#ENTER_YOUR_OWN#"
60+
61+
cool = Message(api_key, api_secret)
62+
try:
63+
i = 0
64+
response = cool.sent()
65+
for data in response['data']:
66+
i += 1
67+
print("Message No.%s" % i)
68+
print("Type : %s" % data['type'])
69+
print("Accepted_time : %s" % data['accepted_time'])
70+
print("Recipient_number : %s" % data['recipient_number'])
71+
print("Group_id : %s" % data['group_id'])
72+
print("Message_id : %s" % data['message_id'])
73+
print("Status : %s" % data['status'])
74+
print("Result_code : %s" % data['result_code'])
75+
print("Result_message : %s" % data['result_message'])
76+
print("Sent_time : %s" % data['sent_time'])
77+
print("Text : %s" % data['text'])
78+
print("Carrier : %s" % data['carrier'])
79+
print("Scheduled_time : %s" % data['scheduled_time'])
80+
81+
except CoolsmsException as e:
82+
print("Error Code : %s" % e.code)
83+
print("Error Message : %s" % e.msg)
84+
```
85+
86+
If you want more examples. Visit to 'http://www.coolsms.co.kr/Python_SDK_Example'.
87+
88+
## Information
89+
90+
Look at the 'http://www.coolsms.co.kr/Python_SDK_Start_here'

examples/coolsms_unit_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf8 -*-
12
# vi:set sw=4 ts=4 expandtab:
23

34
import sys
@@ -20,8 +21,8 @@ def makeSuite(testcase,tests):
2021
# @brief Coolsms Python SDK Unit Test
2122
class CoolsmsUnitTest(unittest.TestCase):
2223

23-
api_key = "NCS57A43A134D2B9"
24-
api_secret = "9BF07E949C74516A70D7C6A4D6B2B0D3"
24+
api_key = "#ENTER_YOUR_OWN#"
25+
api_secret = "#ENTER_YOUR_OWN#"
2526

2627
def setUp(self):
2728
pass
@@ -114,7 +115,7 @@ def test_group_message(self):
114115

115116
## send
116117
try:
117-
cool.send(params)
118+
cool.send(group_id)
118119
except CoolsmsException as e:
119120
# 402는 잔액부족이기 때문에 테스트 실패사유가 안됨
120121
if e.code == 402:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
## @brief This sample code demonstrate how to add messages into group through CoolSMS Rest API
12+
if __name__ == "__main__":
13+
14+
# set api key, api secret
15+
api_key = "#ENTER_YOUR_OWN#"
16+
api_secret = "#ENTER_YOUR_OWN#"
17+
18+
# Options(group_id, to, from, text) are mandatory. must be filled
19+
params = dict()
20+
params["type"] = "sms" # Message type ( sms, lms, mms, ata )
21+
params['to'] = '01000000000' # Recipients Number '01000000000,01000000001'
22+
params['from'] = '01000000000' # Sender number
23+
params['text'] = 'Test Message' # Message
24+
params["group_id"] = "GID57A82D462CBBF" # Group ID
25+
26+
# Optional parameters for your own needs
27+
# params["image_id"] = "image_id" # image_id. type must be set as 'MMS'
28+
# params["refname"] = "" # Reference name
29+
# params["country"] = "82" # Korea(82) Japan(81) America(1) China(86) Default is Korea
30+
# params["datetime"] = "20140106153000" # Format must be(YYYYMMDDHHMISS) 2014 01 06 15 30 00 (2014 Jan 06th 3pm 30 00)
31+
# params["subject"] = "Message Title" # set msg title for LMS and MMS
32+
# params["delay"] = "10") # '0~20' delay messages
33+
# params["sender_key"] = "5554025sa8e61072frrrd5d4cc2rrrr65e15bb64" # 알림톡 사용을 위해 필요합니다. 신청방법 : http://www.coolsms.co.kr/AboutAlimTalk
34+
# params["template_code"] = "C004" # 알림톡 template code 입니다. 자세한 설명은 http://www.coolsms.co.kr/AboutAlimTalk을 참조해주세요.
35+
36+
cool = GroupMessage(api_key, api_secret)
37+
38+
try:
39+
response = cool.add_messages(params)
40+
print("Success Count : %s" % response['success_count'])
41+
print("Error Count : %s" % response['error_count'])
42+
43+
if "error_list" in response:
44+
print("Error List : %s" % response['error_list'])
45+
46+
except CoolsmsException as e:
47+
print("Error Code : %s" % e.code)
48+
print("Error Message : %s" % e.msg)
49+
50+
sys.exit()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
import json
6+
7+
sys.path.insert(0, "../../")
8+
9+
from sdk.api.group_message import GroupMessage
10+
from sdk.exceptions import CoolsmsException
11+
12+
## @brief This sample code demonstrate how to add messages into group through CoolSMS Rest API
13+
if __name__ == "__main__":
14+
15+
# set api key, api secret
16+
api_key = "#ENTER_YOUR_OWN#"
17+
api_secret = "#ENTER_YOUR_OWN#"
18+
19+
# Options(group_id, to, from, text) are mandatory. must be filled
20+
group_id = "GID57A82D462CBBF" # Group ID
21+
22+
json_data = list()
23+
params = dict()
24+
params["type"] = "sms" # Message type ( sms, lms, mms, ata )
25+
params['to'] = '01000000000' # Recipients Number '01000000000,01000000001'
26+
params['from'] = '01000000000' # Sender number
27+
params['text'] = 'Test Message' # Message
28+
29+
# Optional parameters for your own needs
30+
# params["image_id"] = "image_id" # image_id. type must be set as 'MMS'
31+
# params["refname"] = "" # Reference name
32+
# params["country"] = "82" # Korea(82) Japan(81) America(1) China(86) Default is Korea
33+
# params["datetime"] = "20140106153000" # Format must be(YYYYMMDDHHMISS) 2014 01 06 15 30 00 (2014 Jan 06th 3pm 30 00)
34+
# params["subject"] = "Message Title" # set msg title for LMS and MMS
35+
# params["delay"] = "10") # '0~20' delay messages
36+
# params["sender_key"] = "5554025sa8e61072frrrd5d4cc2rrrr65e15bb64" # 알림톡 사용을 위해 필요합니다. 신청방법 : http://www.coolsms.co.kr/AboutAlimTalk
37+
# params["template_code"] = "C004" # 알림톡 template code 입니다. 자세한 설명은 http://www.coolsms.co.kr/AboutAlimTalk을 참조해주세요.
38+
39+
json_data.append(params) # 원하는 만큼 params를 넣어줍니다
40+
json_data = json.dumps(json_data)
41+
42+
cool = GroupMessage(api_key, api_secret)
43+
44+
try:
45+
response = cool.add_messages_json(group_id, json_data)
46+
for data in response:
47+
print("Success Count : %s" % data['success_count'])
48+
print("Error Count : %s" % data['error_count'])
49+
50+
if "error_list" in response:
51+
print("Error List : %s" % response['error_list'])
52+
53+
except CoolsmsException as e:
54+
print("Error Code : %s" % e.code)
55+
print("Error Message : %s" % e.msg)
56+
57+
sys.exit()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
## @brief This sample code demonstrate how to create sms group through CoolSMS Rest API
12+
if __name__ == "__main__":
13+
14+
# set api key, api secret
15+
api_key = "#ENTER_YOUR_OWN#"
16+
api_secret = "#ENTER_YOUR_OWN#"
17+
18+
# Optional parameters for your own needs
19+
params = dict()
20+
# params["charset"] = "utf8" # utf8, euckr default value is utf8
21+
# params["srk"] = "293DIWNEK103" # Solution key
22+
# params["mode"] = "test" # If 'test' value, refund cash to point
23+
# params["only_ata"] = "true" # If 'true' value, only send ata
24+
# params["delay"] = "10" # '0~20' delay messages
25+
# params["force_sms"] = "true"; # true is always send sms ( default true )
26+
# params["app_version"] = "" # A version
27+
28+
cool = GroupMessage(api_key, api_secret)
29+
30+
try:
31+
response = cool.create_group(params)
32+
print("Group ID : %s" % response['group_id'])
33+
34+
except CoolsmsException as e:
35+
print("Error Code : %s" % e.code)
36+
print("Error Message : %s" % e.msg)
37+
38+
sys.exit()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
## @brief This sample code demonstrate how to delete sms group through CoolSMS Rest API
12+
if __name__ == "__main__":
13+
14+
# set api key, api secret
15+
api_key = "#ENTER_YOUR_OWN#"
16+
api_secret = "#ENTER_YOUR_OWN#"
17+
18+
# group_ids is mandatory
19+
group_ids = "GID57A82D462CBBFF" # Group IDs "GID57A82D462CBBFF,GID98A82D462CDBFF ..."
20+
21+
cool = GroupMessage(api_key, api_secret)
22+
23+
try:
24+
response = cool.delete_groups(group_ids)
25+
print("Success Count : %s" % response['success_count'])
26+
print("Error Count : %s" % response['error_count'])
27+
28+
if "error_list" in response:
29+
print("Error List : %s" % response['error_list'])
30+
31+
except CoolsmsException as e:
32+
print("Error Code : %s" % e.code)
33+
print("Error Message : %s" % e.msg)
34+
35+
sys.exit()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
## @brief This sample code demonstrate how to delete messages through CoolSMS Rest API
12+
if __name__ == "__main__":
13+
14+
# set api key, api secret
15+
api_key = "#ENTER_YOUR_OWN#"
16+
api_secret = "#ENTER_YOUR_OWN#"
17+
18+
# group_id, message_ids are mandatory.
19+
group_id = "GID57A82D462CBBF" # Group ID
20+
message_ids = "MID2738AWQIEQQ" # Message IDs "MID29EII1913,MID1839231REE ..."
21+
22+
cool = GroupMessage(api_key, api_secret)
23+
24+
try:
25+
response = cool.delete_messages(group_id, message_ids)
26+
print("Success Count : %s" % response['success_count'])
27+
print("Error Count : %s" % response['error_count'])
28+
29+
if "error_list" in response:
30+
print("Error List : %s" % response['error_list'])
31+
32+
except CoolsmsException as e:
33+
print("Error Code : %s" % e.code)
34+
print("Error Message : %s" % e.msg)
35+
36+
sys.exit()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
## @brief This sample code demonstrate how to check group info through CoolSMS Rest API
12+
if __name__ == "__main__":
13+
14+
# set api key, api secret
15+
api_key = "#ENTER_YOUR_OWN#"
16+
api_secret = "#ENTER_YOUR_OWN#"
17+
18+
# group_id is mandatory.
19+
group_id = "GID57A82D462CBBF"
20+
21+
cool = GroupMessage(api_key, api_secret)
22+
23+
try:
24+
response = cool.get_group_info(group_id)
25+
print("Group ID : %s" % response['group_id'])
26+
print("Message Count : %s" % response['message_count'])
27+
28+
except CoolsmsException as e:
29+
print("Error Code : %s" % e.code)
30+
print("Error Message : %s" % e.msg)
31+
32+
sys.exit()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# vi:set sw=4 ts=4 expandtab:
2+
# -*- coding: utf8 -*-
3+
4+
import sys
5+
6+
sys.path.insert(0, "../../")
7+
8+
from sdk.api.group_message import GroupMessage
9+
from sdk.exceptions import CoolsmsException
10+
11+
12+
## @brief This sample code demonstrate how to check group list through CoolSMS Rest API
13+
if __name__ == "__main__":
14+
15+
# set api key, api secret
16+
api_key = "#ENTER_YOUR_OWN#"
17+
api_secret = "#ENTER_YOUR_OWN#"
18+
19+
cool = GroupMessage(api_key, api_secret)
20+
21+
try:
22+
response = cool.get_group_list()
23+
print("Group List : %s" % response['list'])
24+
25+
except CoolsmsException as e:
26+
print("Error Code : %s" % e.code)
27+
print("Error Message : %s" % e.msg)
28+
29+
sys.exit()

0 commit comments

Comments
 (0)