Connect to Viber Channel

Hello, I’m trying to connect a bot running on localhost to Viber using ngrok. I achieved a basic echo functionality following the Viber Python Bot API | Viber Developers Hub and Viber Python Bot API | Viber Developers Hub but when I try to do the same using a custom InputChannel in Rasa and then after the server runs to run from another script the

from viberbot import Api
from viberbot.api.bot_configuration import BotConfiguration

bot_configuration = BotConfiguration(
    name='xxx',
    avatar='',
    auth_token='xxxxxxxxxxxx'
)
viber = Api(bot_configuration)
viber.set_webhook('http://xxxxxxxxxxxx.ngrok.io')

I get a 405 Method Not Allowed . Can anyone please guide me on how to fix it? In the ViberInput(InputChannel) I have a very basic functionality at that moment to mimic echo.

class ViberInput(InputChannel):
    """Viber input channel implementation. Based on the HTTPInputChannel."""
    
    @classmethod
    def name(cls) -> Text:
        return "viber"

    @classmethod
    def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChannel:
        if not credentials:
            cls.raise_missing_credentials_exception()

        return cls(
            credentials.get("viber_name"),
            credentials.get("avatar"),
            credentials.get("auth_token")
            )

    def __init__(self, viber_name: Text, avatar: Text, auth_token: Text) -> None:
        """Create a Viber input channel.
        """
        self.viber_name = viber_name
        self.avatar = avatar
        self.auth_token = auth_token
        self.viber = Api(
            BotConfiguration(
                name=self.viber_name,
                avatar=self.avatar,
                auth_token=self.auth_token
                )
        )

    def blueprint(
        self, on_new_message: Callable[[UserMessage], Awaitable[Any]]
    ) -> Blueprint:
        viber_webhook = Blueprint("viber_webhook", __name__)

        @viber_webhook.route("/", methods=["POST"])
        async def incoming(request: Request) -> HTTPResponse:
            viber_request = self.viber.parse_request(request.get_data())
            if isinstance(viber_request, ViberMessageRequest):
                message = viber_request.message
                # lets echo back
                self.viber.send_messages(viber_request.sender.id, [
                    message
                ])
            return response.text("success")

        return viber_webhook

What does your credentials.yml configuration look like? Do you have a rest: line and do you see the rest channel endpoint listed when you do the rasa run --enable-api?

Can you do a curl test to the ngrok endpoint and get a response?

Greg

Hello.

the credentials are like

viber.ViberInput:
  viber_name: "xxx"
  avatar: "xxx"
  auth_token: "xxxxxx"

I’ve managed to make it work. Do you think it’s good to make a request in Github and add it to the available channels? If so how should I proceed?

Yes, I would open a Github enhancement request and offer to submit a PR with your channel. Please post a link here to your issue.

1 Like

Okay I’ll wait for the Github enhancement request.

HI @stephens @magda I am trying to integrate my rasa bot to viber. I have no clear idea on how to proceed. Could You Please Help me.

I’m not familiar with Viber but Rasa has two general API endpoints. One for REST and another for Websockets.

It looks like Viber has a process to Create a Chat Extension so that would be the place to start.