+ ts.sendEndSessionMessage(ns.<String>getList("recipient"));
+ } catch (IOException e) {
+ handleIOException(e);
+ } catch (EncapsulatedExceptions e) {
+ handleEncapsulatedExceptions(e);
+ } catch (AssertionError e) {
+ handleAssertionError(e);
+ }
+ } else {
+ String messageText = ns.getString("message");
+ if (messageText == null) {
+ try {
+ messageText = IOUtils.toString(System.in);
+ } catch (IOException e) {
+ System.err.println("Failed to read message from stdin: " + e.getMessage());
+ System.err.println("Aborting sending.");
+ System.exit(1);
+ }
+ }
+
+ try {
+ List<String> attachments = ns.getList("attachment");
+ if (attachments == null) {
+ attachments = new ArrayList<>();
+ }
+ if (ns.getString("group") != null) {
+ byte[] groupId = decodeGroupId(ns.getString("group"));
+ ts.sendGroupMessage(messageText, attachments, groupId);
+ } else {
+ ts.sendMessage(messageText, attachments, ns.<String>getList("recipient"));
+ }