Skip to content

Commit 1f3af5a

Browse files
authored
Merge pull request #6 from cmdotcom/feature/auto-detect-encoding
Add option to add auto detect encoding
2 parents e6f8dd4 + 4365bad commit 1f3af5a

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ By calling `SendTextMessage` and providing message text, sender name, recipient
2828
client.sendTextMessage("Message Text", "TestSender", new String[] {"00316012345678"});
2929

3030
```
31+
## Sending a message with auto detect encoding
32+
By using the `MessageBuilder` it is possible to send messages with auto detect encoding,
3133

34+
It is possible to let our gateway detect the encoding for you by including the type: auto setting.
35+
In case it detects characters that are not part of the GSM character set, the message will be delivered as Unicode.
36+
37+
see our API docs for more info https://docs.cmtelecom.com/en/api/business-messaging-api/1.0/index/
38+
39+
```cs
40+
MessagingClient client = new MessagingClient("YourProductToken");
41+
MessageBuilder builder = new MessageBuilder("Message Text", "auto", "TestSender", new String[] {"00316012345678"});
42+
43+
Message message = builder.Build();
44+
45+
client.sendMessage(message);
46+
```
3247

3348
## Sending a rich message
3449
By using the `MessageBuilder` it is possible to create images with media for channels such as WhatsApp and Viber
@@ -72,9 +87,9 @@ Sending an message returns the response body
7287

7388
MessagingClient client = new MessagingClient("YourProductToken");
7489

75-
MessageBuilder builder = new MessageBuilder("Template Test", "CM.COM", new String[] {"0031636170815"});
90+
MessageBuilder builder = new MessageBuilder("Template Test", "CM.COM", new String[] {"0031636170815"});
7691

77-
builder.WithAllowedChannels(new Channel[] {Channel.WhatsApp});
92+
builder.WithAllowedChannels(new Channel[] {Channel.WhatsApp});
7893

7994
TemplateMessage template = new TemplateMessage();
8095

@@ -91,14 +106,14 @@ builder.WithAllowedChannels(new Channel[] {Channel.WhatsApp});
91106
"image/png"))}),
92107
new TemplateComponents("body",
93108
new TemplateParameters[] { new TemplateParameters("text", "TestMessage"),
94-
new TemplateParameters("text", "CM.Com")})};
109+
new TemplateParameters("text", "Dutch GP")})};
95110

96111

97-
builder.WithTemplate(template);
112+
builder.WithTemplate(template);
98113

99-
Message message = builder.Build();
114+
Message message = builder.Build();
100115

101-
client.sendMessage(message);
116+
client.sendMessage(message);
102117
```
103118

104119

src/main/java/com/cmtelecom/text/sdk/MessageBuilder.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,26 @@ public MessageBuilder(String messageText, String from,String[] to)
3737
}
3838

3939
this.message = new Message(new Body(messageText), from, recipientList);
40-
4140
}
4241

42+
/// <summary>
43+
/// Creates a new MessageBuilder with auto detect encoding
44+
/// </summary>
45+
/// <param name="messageText"></param>
46+
/// <param name="from"></param>
47+
/// <param name="to"></param>
48+
public MessageBuilder(String messageText, String type, String from,String[] to)
49+
{
50+
List<Recipient> recipientList = new ArrayList<>();
51+
for (String number : to) {
52+
Recipient r = new Recipient();
53+
r.Number = number;
54+
recipientList.add(r);
55+
56+
}
57+
58+
this.message = new Message(new Body(messageText, type), from, recipientList);
59+
}
4360

4461
/// <summary>
4562
/// Constructs the message.

src/main/java/com/cmtelecom/text/sdk/models/Body.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ public class Body {
3535
public Body(String content) {
3636
this.Content = content;
3737
}
38+
39+
public Body(String content, String type) {
40+
this.Content = content;
41+
this.Type = type;
42+
}
3843
}

target/maven-archiver/pom.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Generated by Maven
2-
#Tue Feb 04 16:29:52 CET 2020
2+
#Thu Mar 26 09:32:54 CET 2020
33
groupId=com.github.cmdotcom
44
artifactId=text-sdk-java
55
version=1.0-SNAPSHOT

0 commit comments

Comments
 (0)