-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
224 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
generators/bdk/java/templates/common/GifFormActivity.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package <%= basePackage %>; | ||
|
||
import com.symphony.bdk.core.activity.ActivityMatcher; | ||
import com.symphony.bdk.core.activity.form.FormReplyActivity; | ||
import com.symphony.bdk.core.activity.form.FormReplyContext; | ||
import com.symphony.bdk.core.activity.model.ActivityInfo; | ||
import com.symphony.bdk.core.activity.model.ActivityType; | ||
import com.symphony.bdk.core.service.MessageService; | ||
<% if (framework == 'spring') { %> | ||
import org.springframework.stereotype.Component; | ||
@Component<% } %> | ||
public class GifFormActivity extends FormReplyActivity<%-'<'%>FormReplyContext<%-'>'%> { | ||
|
||
private final MessageService messageService; | ||
|
||
public GifFormActivity(MessageService messageService) { | ||
this.messageService = messageService; | ||
} | ||
|
||
@Override | ||
public ActivityMatcher<%-'<'%>FormReplyContext<%-'>'%> matcher() { | ||
return context -> "gif-category-form".equals(context.getFormId()) | ||
&& "submit".equals(context.getFormValue("action")); | ||
} | ||
|
||
@Override | ||
public void onActivity(FormReplyContext context) { | ||
final String category = context.getFormValue("category"); | ||
final String message = "<%-'<'%>messageML<%-'>'%>Received category '" + category + "'<%-'<'%>/messageML<%-'>'%>"; | ||
this.messageService.send(context.getSourceEvent().getStream(), message); | ||
} | ||
|
||
@Override | ||
protected ActivityInfo info() { | ||
return new ActivityInfo().type(ActivityType.FORM) | ||
.name("Gif Display category form command") | ||
.description("\"Form handler for the Gif Category form\""); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
generators/bdk/java/templates/java/BotApplication.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package <%= basePackage %>; | ||
|
||
import com.symphony.bdk.core.SymphonyBdk; | ||
import com.symphony.bdk.template.api.TemplateException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.symphony.bdk.gen.api.model.V4UserJoinedRoom; | ||
import com.symphony.bdk.gen.api.model.V4Initiator; | ||
import com.symphony.bdk.core.service.datafeed.RealTimeEventListener; | ||
import static com.symphony.bdk.core.config.BdkConfigLoader.loadFromClasspath; | ||
import static com.symphony.bdk.core.activity.command.SlashCommand.slash; | ||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.singletonMap; | ||
|
||
/** | ||
* Simple Bot Application. | ||
*/ | ||
public class BotApplication { | ||
|
||
/** The Logger */ | ||
private static final Logger log = LoggerFactory.getLogger(BotApplication.class); | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
// Initialize BDK entry point | ||
final SymphonyBdk bdk = new SymphonyBdk(loadFromClasspath("/config.yaml")); | ||
|
||
// Register a "slash" activity | ||
bdk.activities().register(slash("/gif", false, context -> { | ||
try { | ||
bdk.messages().send(context.getStreamId(), "/templates/gif.ftl", emptyMap()); | ||
} catch (TemplateException e) { | ||
log.error("Unable to load template", e); | ||
} | ||
})); | ||
|
||
// Register a "formReply" activity that handles the Gif category form submission | ||
bdk.activities().register(new GifFormActivity(bdk.messages())); | ||
|
||
// Subscribe to 'onUserJoinedRoom' Real Time Event | ||
bdk.datafeed().subscribe(new RealTimeEventListener() { | ||
|
||
@Override | ||
public void onUserJoinedRoom(V4Initiator initiator, V4UserJoinedRoom event) { | ||
final String userDisplayName = event.getAffectedUser().getDisplayName(); | ||
try { | ||
bdk.messages().send(event.getStream(), "/templates/welcome.ftl", singletonMap("name", userDisplayName)); | ||
} catch (TemplateException e) { | ||
log.error("Unable to load template", e); | ||
} | ||
} | ||
}); | ||
|
||
// finally, start the datafeed read loop | ||
bdk.datafeed().start(); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
generators/bdk/java/templates/java/src/main/java/BotApplication.java.ejs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
generators/bdk/java/templates/spring/GifSlashHandler.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package <%= basePackage %>; | ||
|
||
import static java.util.Collections.emptyMap; | ||
|
||
import com.symphony.bdk.core.activity.command.CommandContext; | ||
import com.symphony.bdk.core.service.MessageService; | ||
import com.symphony.bdk.spring.annotation.Slash; | ||
import com.symphony.bdk.template.api.TemplateException; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class GifSlashHandler { | ||
|
||
private final MessageService messageService; | ||
|
||
public GifSlashHandler(MessageService messageService) { | ||
this.messageService = messageService; | ||
} | ||
|
||
@Slash(value = "/gif", mentionBot = false) | ||
public void onSlashGif(CommandContext context) throws TemplateException { | ||
this.messageService.send(context.getStreamId(), "/templates/gif.ftl", emptyMap()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
generators/bdk/java/templates/spring/OnUserJoinedRoomListener.java.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package <%= basePackage %>; | ||
|
||
import com.symphony.bdk.core.service.MessageService; | ||
import com.symphony.bdk.core.service.datafeed.RealTimeEventListener; | ||
import com.symphony.bdk.gen.api.model.V4Initiator; | ||
import com.symphony.bdk.gen.api.model.V4UserJoinedRoom; | ||
import com.symphony.bdk.template.api.TemplateException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static java.util.Collections.singletonMap; | ||
|
||
@Component | ||
public class OnUserJoinedRoomListener implements RealTimeEventListener { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(OnUserJoinedRoomListener.class); | ||
|
||
private final MessageService messageService; | ||
|
||
@Autowired | ||
public OnUserJoinedRoomListener(MessageService messageService) { | ||
this.messageService = messageService; | ||
} | ||
|
||
@Override | ||
public void onUserJoinedRoom(V4Initiator initiator, V4UserJoinedRoom event) { | ||
final String userDisplayName = event.getAffectedUser().getDisplayName(); | ||
try { | ||
this.messageService.send(event.getStream(), "/templates/welcome.ftl", singletonMap("name", userDisplayName)); | ||
} catch (TemplateException e) { | ||
log.error("Unable to load template", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.