Skip to content

Commit a15b2a1

Browse files
committed
feat: Add network_code to InboundMessage
1 parent 9ad5f58 commit a15b2a1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
# [8.7.0] - 2024-05-??
7+
# [8.7.0] - 2024-05-16
88
- Added missing supported languages to `TextToSpeechLanguage` enum
99
- Added `ttl` field to outbound MMS messages
1010
- Added message reply context to Whatsapp outbound requests
11+
- Added network code to `InboundMessage`
1112

1213
# [8.6.0] - 2024-04-18
1314
- Added Experience Composer to Video API

src/main/java/com/vonage/client/messages/InboundMessage.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class InboundMessage extends JsonableBaseObject {
3838

3939
protected static class UrlWrapper extends JsonableBaseObject {
4040
@JsonProperty("url") protected URI url;
41+
@JsonProperty("name") protected String name;
4142
}
4243

4344
protected static class UrlWrapperWithCaption extends UrlWrapper {
@@ -48,6 +49,10 @@ protected static class Whatsapp extends JsonableBaseObject {
4849
@JsonProperty("referral") protected Referral referral;
4950
}
5051

52+
protected static class Origin extends JsonableBaseObject {
53+
@JsonProperty("network_code") protected String networkCode;
54+
}
55+
5156
protected InboundMessage() {}
5257

5358
@JsonAnySetter protected Map<String, Object> unknownProperties;
@@ -79,6 +84,7 @@ protected InboundMessage() {}
7984
@JsonProperty("order") protected Order whatsappOrder;
8085
@JsonProperty("usage") protected MessageStatus.Usage usage;
8186
@JsonProperty("sms") protected SmsInboundMetadata smsMetadata;
87+
@JsonProperty("origin") protected Origin origin;
8288

8389
/**
8490
* This is a catch-all method which encapsulates all fields in the response JSON
@@ -330,6 +336,19 @@ public SmsInboundMetadata getSmsMetadata() {
330336
return smsMetadata;
331337
}
332338

339+
/**
340+
* If the {@linkplain #getChannel()} is {@linkplain Channel#SMS} or {@linkplain Channel#MMS},
341+
* return the network code from which the message originated (if available).
342+
*
343+
* @return The origin network code if applicable, or {@code null} if unknown.
344+
*
345+
* @since 8.7.0
346+
*/
347+
@JsonIgnore
348+
public String getNetworkCode() {
349+
return origin != null ? origin.networkCode : null;
350+
}
351+
333352
/**
334353
* If the {@linkplain #getChannel()} is {@linkplain Channel#WHATSAPP} and a content referral is present in
335354
* the message, returns the metadata related to the post or advertisement that the user clicked on.

src/test/java/com/vonage/client/messages/InboundMessageTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,15 @@ public void testWhatsappReferralOnly() {
358358
assertEquals(sourceType, referral.getSourceType());
359359
assertEquals(URI.create(sourceUrl), referral.getSourceUrl());
360360
}
361+
362+
@Test
363+
public void testOriginOnly() {
364+
String networkCode = "12534", json = "{\n" +
365+
" \"origin\": {\n" +
366+
" \"network_code\": \""+networkCode+"\"\n" +
367+
" }\n" +
368+
"}";
369+
var im = InboundMessage.fromJson(json);
370+
assertEquals(networkCode, im.getNetworkCode());
371+
}
361372
}

0 commit comments

Comments
 (0)