Skip to content

Commit 8d48792

Browse files
Merge pull request #5 from cmdotcom/improve_examples
Improve examples
2 parents e1cfedf + f31f08e commit 8d48792

8 files changed

+52
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.idea
2+
venv

CMText/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#project Version
2-
__version__ = '1.1.2'
2+
__version__ = '1.1.3'

Examples/Multiple_Message_Example.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import os
12
from CMText.TextClient import TextClient
23

3-
# Message to be send
4-
message = 'Examples message to be send'
5-
message2 = 'Examples 2 message to be send'
4+
# fetch the API key from environment variables
5+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
6+
if UNIQUE_API_KEY is None:
7+
print('Please fill an environment variable named CM_API_KEY with your API key.')
8+
9+
# Message to be sent
10+
message = 'Examples message to be sent'
11+
message2 = 'Examples 2 message to be sent'
612

713
# Recipients
814
to = ['003156789000', '002134567890']

Examples/Rich_Message_Example.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import os
12
from CMText.TextClient import TextClient
23

3-
# Message to be send
4-
message = 'Examples message to be send'
4+
# fetch the API key from environment variables
5+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
6+
if UNIQUE_API_KEY is None:
7+
print('Please fill an environment variable named CM_API_KEY with your API key.')
58

6-
# Media to be send
9+
# Message to be sent
10+
message = 'Examples message to be sent'
11+
12+
# Media to be sent
713
media = {
814
"mediaName": "conversational-commerce",
915
"mediaUri": "https://www.cm.com/cdn/cm/cm.png",
@@ -26,4 +32,4 @@
2632
response = client.send()
2733

2834
# Print response
29-
print(response.text)
35+
print(response.text)

Examples/Single_Message_Example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import os
12
from CMText.TextClient import TextClient
23

3-
# Message to be send
4-
message = 'Examples message to be send'
4+
# fetch the API key from environment variables
5+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
6+
if UNIQUE_API_KEY is None:
7+
print('Please fill an environment variable named CM_API_KEY with your API key.')
8+
9+
# Message to be sent
10+
message = 'Examples message to be sent'
511

612
# Recipients
713
to = ['003156789000', '002134567890']

Examples/Whatsapp_Template_Message_Example.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
import os
12
from CMText.TextClient import TextClient
23
from CMText.WhatsappTemplate import WhatsappTemplate
34

4-
# Your api-Key
5-
key = 'Your-Key'
5+
# fetch the API key from environment variables
6+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
7+
if UNIQUE_API_KEY is None:
8+
print('Please fill an environment variable named CM_API_KEY with your API key.')
69

710
# Recipients
8-
to = ['00123456789','00986837265']
11+
to = ['00123456789', '00986837265']
912

1013
# Template
1114
template_namespace = "Your_Template_Namespace"
1215
template_element_name = "Your_Template_Name"
1316
template = WhatsappTemplate(template_namespace, template_element_name)
1417

1518
# Instantiate client with your own api-key
16-
client = TextClient(apikey=key)
19+
client = TextClient(apikey=UNIQUE_API_KEY)
1720

1821
# Add message to queue
1922
client.AddWhatsappTemplateMessage(from_='pythonSDK', to=to, template=template)

Examples/Whatsapp_Template_with Media.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import os
12
from CMText.TextClient import TextClient
23
from CMText.WhatsappTemplate import WhatsappTemplate
34

4-
# Your api-Key
5-
key = 'Your-Key'
5+
# fetch the API key from environment variables
6+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
7+
if UNIQUE_API_KEY is None:
8+
print('Please fill an environment variable named CM_API_KEY with your API key.')
69

710
# Recipients
8-
to = ['00123456789','00986837265']
11+
to = ['00123456789', '00986837265']
912

1013
# Template
1114
template_namespace = "Your_Template_Namespace"
@@ -50,4 +53,4 @@
5053
response = client.send()
5154

5255
# Response is an object of type: https://www.w3schools.com/python/ref_requests_response.asp
53-
print(response.text)
56+
print(response.text)

Examples/Whatsapp_Template_with_Components.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import os
12
from CMText.TextClient import TextClient
23
from CMText.WhatsappTemplate import WhatsappTemplate
34

4-
# Your api-Key
5-
key = 'Your-Key'
5+
# fetch the API key from environment variables
6+
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
7+
if UNIQUE_API_KEY is None:
8+
print('Please fill an environment variable named CM_API_KEY with your API key.')
69

710
# Recipients
8-
to = ['00123456789','00986837265']
11+
to = ['00123456789', '00986837265']
912

1013
# Template
1114
template_namespace = "Your_Template_Namespace"
@@ -35,7 +38,7 @@
3538
template = WhatsappTemplate(template_namespace, template_element_name, template_parameters)
3639

3740
# Instantiate client with your own api-key
38-
client = TextClient(apikey=key)
41+
client = TextClient(apikey=UNIQUE_API_KEY)
3942

4043
# Add message to queue
4144
client.AddWhatsappTemplateMessage(from_='pythonSDK', to=to, template=template)
@@ -44,4 +47,4 @@
4447
response = client.send()
4548

4649
# Response is an object of type: https://www.w3schools.com/python/ref_requests_response.asp
47-
print(response.text)
50+
print(response.text)

0 commit comments

Comments
 (0)