Skip to content

Commit b72ff20

Browse files
committed
Added vCard support when sharing contacts: added the field vcard to the objects Contact, InlineQueryResultContact, InputContactMessageContent and the method sendContact
1 parent 87301d4 commit b72ff20

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

library/src/main/java/com/pengrad/telegrambot/model/Contact.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Contact implements Serializable {
1313
private String first_name;
1414
private String last_name;
1515
private Integer user_id;
16+
private String vcard;
1617

1718
public String phoneNumber() {
1819
return phone_number;
@@ -30,18 +31,22 @@ public Integer userId() {
3031
return user_id;
3132
}
3233

34+
public String vcard() {
35+
return vcard;
36+
}
37+
3338
@Override
3439
public boolean equals(Object o) {
3540
if (this == o) return true;
3641
if (o == null || getClass() != o.getClass()) return false;
3742

3843
Contact contact = (Contact) o;
3944

40-
if (phone_number != null ? !phone_number.equals(contact.phone_number) : contact.phone_number != null)
41-
return false;
45+
if (phone_number != null ? !phone_number.equals(contact.phone_number) : contact.phone_number != null) return false;
4246
if (first_name != null ? !first_name.equals(contact.first_name) : contact.first_name != null) return false;
4347
if (last_name != null ? !last_name.equals(contact.last_name) : contact.last_name != null) return false;
44-
return user_id != null ? user_id.equals(contact.user_id) : contact.user_id == null;
48+
if (user_id != null ? !user_id.equals(contact.user_id) : contact.user_id != null) return false;
49+
return vcard != null ? vcard.equals(contact.vcard) : contact.vcard == null;
4550
}
4651

4752
@Override
@@ -56,6 +61,7 @@ public String toString() {
5661
", first_name='" + first_name + '\'' +
5762
", last_name='" + last_name + '\'' +
5863
", user_id=" + user_id +
64+
", vcard='" + vcard + '\'' +
5965
'}';
6066
}
6167
}

library/src/main/java/com/pengrad/telegrambot/model/request/InlineQueryResultContact.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class InlineQueryResultContact extends InlineQueryResult<InlineQueryResul
1313
private String first_name;
1414

1515
private String last_name;
16+
private String vcard;
1617
private String thumb_url;
1718
private Integer thumb_width;
1819
private Integer thumb_height;
@@ -28,6 +29,11 @@ public InlineQueryResultContact lastName(String lastName) {
2829
return this;
2930
}
3031

32+
public InlineQueryResultContact vcard(String vcard) {
33+
this.vcard = vcard;
34+
return this;
35+
}
36+
3137
public InlineQueryResultContact thumbUrl(String thumbUrl) {
3238
this.thumb_url = thumbUrl;
3339
return this;

library/src/main/java/com/pengrad/telegrambot/model/request/InputContactMessageContent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class InputContactMessageContent extends InputMessageContent implements S
1212
private String phone_number;
1313
private String first_name;
1414
private String last_name;
15+
private String vcard;
1516

1617
public InputContactMessageContent(String phoneNumber, String firstName) {
1718
this.phone_number = phoneNumber;
@@ -22,4 +23,9 @@ public InputContactMessageContent lastName(String lastName) {
2223
this.last_name = lastName;
2324
return this;
2425
}
26+
27+
public InputContactMessageContent vcard(String vcard) {
28+
this.vcard = vcard;
29+
return this;
30+
}
2531
}

library/src/main/java/com/pengrad/telegrambot/request/SendContact.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public SendContact(Object chatId, String phoneNumber, String firstName) {
1515
public SendContact lastName(String lastName) {
1616
return add("last_name", lastName);
1717
}
18+
19+
public SendContact vcard(String vcard) {
20+
return add("vcard", vcard);
21+
}
1822
}

library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ public void answerInline() {
254254
new InputTextMessageContent("message").disableWebPagePreview(false).parseMode(ParseMode.HTML))
255255
.url(someUrl).hideUrl(true).description("desc").thumbUrl(someUrl).thumbHeight(100).thumbWidth(100),
256256
new InlineQueryResultArticle("2", "title",
257-
new InputContactMessageContent("123123123", "na,e").lastName("lastName")),
257+
new InputContactMessageContent("123123123", "na,e").lastName("lastName").vcard("qr vcard")),
258258
new InlineQueryResultArticle("3", "title", new InputLocationMessageContent(50f, 50f).livePeriod(60)),
259259
new InlineQueryResultArticle("4", "title",
260260
new InputVenueMessageContent(50f, 50f, "title", "address").foursquareId("sqrId").foursquareType("frType")),
261261
new InlineQueryResultArticle("5", "title", "message"),
262262
new InlineQueryResultAudio("6", someUrl, "title").caption("cap <b>bold</b>").parseMode(ParseMode.HTML).performer("perf").audioDuration(100),
263-
new InlineQueryResultContact("7", "123123123", "name").lastName("lastName")
263+
new InlineQueryResultContact("7", "123123123", "name").lastName("lastName").vcard("tt vcard")
264264
.thumbUrl(someUrl).thumbHeight(100).thumbWidth(100),
265265
new InlineQueryResultDocument("8", someUrl, "title", "application/pdf").caption("cap <b>bold</b>").parseMode(ParseMode.HTML).description("desc")
266266
.thumbUrl(someUrl).thumbHeight(100).thumbWidth(100),
@@ -735,11 +735,12 @@ public void sendVenue() {
735735

736736
@Test
737737
public void sendContact() {
738-
String phone = "000111", name = "first", lastName = "last";
739-
Contact contact = bot.execute(new SendContact(chatId, phone, name).lastName(lastName)).message().contact();
738+
String phone = "000111", name = "first", lastName = "last", vcard = "ok vcard";
739+
Contact contact = bot.execute(new SendContact(chatId, phone, name).lastName(lastName).vcard(vcard)).message().contact();
740740
assertEquals(phone, contact.phoneNumber());
741741
assertEquals(name, contact.firstName());
742742
assertEquals(lastName, contact.lastName());
743+
assertEquals(vcard, contact.vcard());
743744
assertNull(contact.userId());
744745
}
745746

0 commit comments

Comments
 (0)