All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viber.bot.api.MessageDestination Maven / Gradle / Ivy

Go to download

Use this library to communicate with the Viber API to develop a bot for https://developers.viber.com/.

The newest version!
package com.viber.bot.api;

import java.util.Collections;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.viber.bot.profile.UserProfile;

import static com.google.common.base.Preconditions.checkNotNull;

public class MessageDestination {

	@Nonnull
	private final UserProfile userProfile;
	
	@Nullable
	private final String chatId;
	
	@Nullable
	private final String replyType;

	public MessageDestination(final @Nonnull UserProfile userProfile) {
		this(userProfile, null, null);
	}
	
	MessageDestination(final @Nonnull UserProfile userProfile, final @Nullable String chatId, final @Nullable String replyType) {
		this.userProfile = checkNotNull(userProfile);
		this.chatId = chatId;
		this.replyType = replyType;
	}

	public UserProfile getUserProfile() {
		return userProfile;
	}

	@Nullable
	public String getChatId() {
		return chatId;
	}

	@Nullable
	public String getReplyType() {
		return replyType;
	}
	
	public Map getReceiverParams() {
		if (Strings.isNullOrEmpty(chatId)) {
			return Collections.singletonMap("receiver", userProfile.getId());
		}
		
		if (!Strings.isNullOrEmpty(replyType) && replyType.equalsIgnoreCase("message")) {
			return Collections.singletonMap("chat_id", chatId);
		}
		
		return ImmutableMap.of("receiver", userProfile.getId(), "chat_id", chatId);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((chatId == null) ? 0 : chatId.hashCode());
		result = prime * result + ((replyType == null) ? 0 : replyType.hashCode());
		result = prime * result + ((userProfile == null) ? 0 : userProfile.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		MessageDestination other = (MessageDestination) obj;
		if (chatId == null) {
			if (other.chatId != null) return false;
		}
		else if (!chatId.equals(other.chatId)) return false;
		if (replyType == null) {
			if (other.replyType != null) return false;
		}
		else if (!replyType.equals(other.replyType)) return false;
		if (userProfile == null) {
			if (other.userProfile != null) return false;
		}
		else if (!userProfile.equals(other.userProfile)) return false;
		return true;
	}

	@Override
	public String toString() {
		return "MessageDestinationProfile [userProfile=" + userProfile + ", chatId=" + chatId + ", replyType=" + replyType + "]";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy