- List<String> attachments = ns.getList("attachment");
- if (attachments == null) {
- attachments = new ArrayList<>();
- }
- long timestamp;
- if (ns.getString("group") != null) {
- byte[] groupId = Util.decodeGroupId(ns.getString("group"));
- timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
- } else {
- timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
+ var results = m.sendMessage(new Message(messageText,
+ attachments,
+ mentions,
+ Optional.ofNullable(quote),
+ Optional.ofNullable(sticker)), recipientIdentifiers);
+ outputResult(outputWriter, results);
+ } catch (AttachmentInvalidException | IOException e) {
+ throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
+ .getSimpleName() + ")", e);
+ } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
+ throw new UserErrorException(e.getMessage());
+ } catch (UnregisteredRecipientException e) {
+ throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
+ } catch (InvalidStickerException e) {
+ throw new UserErrorException("Failed to send sticker: " + e.getMessage(), e);
+ }
+ }
+
+ private List<Message.Mention> parseMentions(
+ final Manager m, final List<String> mentionStrings
+ ) throws UserErrorException {
+ List<Message.Mention> mentions;
+ final Pattern mentionPattern = Pattern.compile("([0-9]+):([0-9]+):(.+)");
+ mentions = new ArrayList<>();
+ for (final var mention : mentionStrings) {
+ final var matcher = mentionPattern.matcher(mention);
+ if (!matcher.matches()) {
+ throw new UserErrorException("Invalid mention syntax ("
+ + mention
+ + ") expected 'start:end:recipientNumber'");