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

com.viber.bot.Response 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;

import com.google.common.util.concurrent.ListenableFuture;
import com.viber.bot.api.ApiException;
import com.viber.bot.api.MessageDestination;
import com.viber.bot.api.ViberBot;
import com.viber.bot.message.Message;
import com.viber.bot.message.TextMessage;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.Collection;
import static com.google.common.base.Preconditions.checkNotNull;

@Immutable
public class Response {

    private final MessageDestination destination;
    private final ViberBot bot;

    public Response(final @Nonnull MessageDestination destination, final @Nonnull ViberBot bot) {
    	this.destination = checkNotNull(destination);
    	this.bot = checkNotNull(bot);
	}

	/**
     * Shorthand for {@link ViberBot#sendMessage(MessageDestination, Collection)}
     * Where the {@link MessageDestination} is already set.
     *
     * @param messages collection of messages to be sent
     * @return future which contains a collection of message tokens as strings, that may throw {@link ApiException}.
     * @see ViberBot#sendMessage(MessageDestination, Collection)
     */
    public ListenableFuture> send(final @Nonnull Collection messages) {
        return bot.sendMessage(destination, messages);
    }

    /**
     * Shorthand for {@link ViberBot#sendMessage(MessageDestination, Message...)}
     * Where the {@link MessageDestination} is already set.
     *
     * @param messages collection of messages to be sent
     * @return future which contains a collection of message tokens as strings, that may throw {@link ApiException}.
     * @see ViberBot#sendMessage(MessageDestination, Message...)
     */
    public ListenableFuture> send(final @Nonnull Message... messages) {
        return bot.sendMessage(destination, messages);
    }

    /**
     * Shorthand for {@link ViberBot#sendMessage(MessageDestination, Message...)}
     * The method will create a {@link TextMessage} for you with the String provided to it.
     *
     * @param textMessage string to be as text for the message
     * @return future which contains a collection of message tokens as strings, that may throw {@link ApiException}.
     * @see ViberBot#sendMessage(MessageDestination, Message...)
     */
    public ListenableFuture> send(final @Nonnull String textMessage) {
        return bot.sendMessage(destination, new TextMessage(textMessage));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy