001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.messages.whatsapp; 017 018import com.fasterxml.jackson.annotation.JsonCreator; 019import com.fasterxml.jackson.annotation.JsonProperty; 020import com.fasterxml.jackson.annotation.JsonValue; 021import com.vonage.client.JsonableBaseObject; 022import com.vonage.client.messages.internal.MessagePayload; 023import java.net.URI; 024import java.util.UUID; 025 026/** 027 * Represents a {@linkplain com.vonage.client.messages.MessageType#REACTION} message. 028 * 029 * @since 8.11.0 030 */ 031public final class Reaction extends JsonableBaseObject { 032 private final Action action; 033 private final String emoji; 034 035 /** 036 * Unreact to a message. 037 */ 038 public Reaction() { 039 action = Action.UNREACT; 040 emoji = null; 041 } 042 043 /** 044 * Create a new reaction to a message. 045 * 046 * @param emoji The reaction emoji to use. 047 */ 048 public Reaction(String emoji) { 049 action = Action.REACT; 050 this.emoji = emoji; 051 } 052 053 /** 054 * The action to take. If {@link Action#REACT}, then an emoji must be set. 055 * 056 * @return The action taken as an enum. 057 */ 058 @JsonProperty("action") 059 public Action getAction() { 060 return action; 061 } 062 063 /** 064 * The emoji used as a reaction. 065 * 066 * @return The emoji as a string, or {@code null} if not applicable. 067 */ 068 @JsonProperty("emoji") 069 public String getEmoji() { 070 return emoji; 071 } 072 073 /** 074 * Represents the action to be taken. 075 */ 076 public enum Action { 077 /** 078 * React to a message. 079 */ 080 REACT, 081 082 /** 083 * Remove a reaction to a message. 084 */ 085 UNREACT; 086 087 @JsonValue 088 @Override 089 public String toString() { 090 return name().toLowerCase(); 091 } 092 093 @JsonCreator 094 public static Action fromString(String value) { 095 if (value == null) return null; 096 return Action.valueOf(value.toUpperCase()); 097 } 098 } 099}