本文整理汇总了Java中com.github.messenger4j.send.templates.GenericTemplate类的典型用法代码示例。如果您正苦于以下问题:Java GenericTemplate类的具体用法?Java GenericTemplate怎么用?Java GenericTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericTemplate类属于com.github.messenger4j.send.templates包,在下文中一共展示了GenericTemplate类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendGenericMessage
import com.github.messenger4j.send.templates.GenericTemplate; //导入依赖的package包/类
private void sendGenericMessage(String recipientId, List<ResponseData> items) throws MessengerApiException, MessengerIOException {
GenericTemplate.Element.ListBuilder genericTemplate = GenericTemplate.newBuilder().addElements();
for(ResponseData item : items) {
GenericTemplate.Element.Builder element = genericTemplate.addElement(item.getTitle());
if (item.getImage() != null) {
element.imageUrl(Utility.generateImageUrl(baseUrl, item.getImage()));
}
if (item.getText() != null) {
element.subtitle(processSubtitle(item.getText()));
}
List<ResponseData.Button> buttons = item.getButtons();
if(buttons != null && buttons.size() > 0) {
com.github.messenger4j.send.buttons.Button.ListBuilder fbButtons = com.github.messenger4j.send.buttons.Button.newListBuilder();
for(ResponseData.Button button : buttons) {
switch(button.getButtonType()) {
case ResponseType.BUTTON_LINK:
fbButtons.addUrlButton(button.getTitle(), button.getUri()).toList();
break;
case ResponseType.BUTTON_PARAM:
fbButtons.addPostbackButton(button.getTitle(), button.getUri()).toList();
break;
}
}
element.buttons(fbButtons.build());
}
element.toList();
}
sendClient.sendTemplate(recipientId, genericTemplate.done().build());
}
示例2: sendGenericMessage
import com.github.messenger4j.send.templates.GenericTemplate; //导入依赖的package包/类
private void sendGenericMessage(String recipientId) throws MessengerApiException, MessengerIOException {
final List<Button> riftButtons = Button.newListBuilder()
.addUrlButton("Open Web URL", "https://www.oculus.com/en-us/rift/").toList()
.addPostbackButton("Call Postback", "Payload for first bubble").toList()
.build();
final List<Button> touchButtons = Button.newListBuilder()
.addUrlButton("Open Web URL", "https://www.oculus.com/en-us/touch/").toList()
.addPostbackButton("Call Postback", "Payload for second bubble").toList()
.build();
final GenericTemplate genericTemplate = GenericTemplate.newBuilder()
.addElements()
.addElement("rift")
.subtitle("Next-generation virtual reality")
.itemUrl("https://www.oculus.com/en-us/rift/")
.imageUrl(RESOURCE_URL + "/assets/rift.png")
.buttons(riftButtons)
.toList()
.addElement("touch")
.subtitle("Your Hands, Now in VR")
.itemUrl("https://www.oculus.com/en-us/touch/")
.imageUrl(RESOURCE_URL + "/assets/touch.png")
.buttons(touchButtons)
.toList()
.done()
.build();
this.sendClient.sendTemplate(recipientId, genericTemplate);
}
开发者ID:messenger4j,项目名称:messenger4j-spring-boot-quickstart-template,代码行数:32,代码来源:MessengerPlatformCallbackHandler.java