All Projects → mileusna → Viber

mileusna / Viber

Licence: mit
Viber messaging/chatbot for Go/Golang

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Viber

Hangoutsbot
Google Hangouts bot
Stars: ✭ 578 (+3300%)
Mutual labels:  chatbot
Yoda
Wise and powerful personal assistant, available in your nearest terminal
Stars: ✭ 674 (+3864.71%)
Mutual labels:  chatbot
Botkube
An app that helps you monitor your Kubernetes cluster, debug critical deployments & gives recommendations for standard practices
Stars: ✭ 804 (+4629.41%)
Mutual labels:  chatbot
Deeppavlov
An open source library for deep learning end-to-end dialog systems and chatbots.
Stars: ✭ 5,525 (+32400%)
Mutual labels:  chatbot
Neuraldialogpapers
Summary of deep learning models for dialog systems (Tiancheng Zhao LTI, CMU)
Stars: ✭ 641 (+3670.59%)
Mutual labels:  chatbot
Chatui
The UI design language and React library for Conversational UI
Stars: ✭ 684 (+3923.53%)
Mutual labels:  chatbot
Node Telegram Bot Api
Telegram Bot API for NodeJS
Stars: ✭ 5,782 (+33911.76%)
Mutual labels:  chatbot
Tensorlayer
Deep Learning and Reinforcement Learning Library for Scientists and Engineers 🔥
Stars: ✭ 6,796 (+39876.47%)
Mutual labels:  chatbot
Awesome Chatops
🤖 A collection of awesome things about ChatOps – managing operations through a chat
Stars: ✭ 648 (+3711.76%)
Mutual labels:  chatbot
Seq2seq Chatbot
Chatbot in 200 lines of code using TensorLayer
Stars: ✭ 777 (+4470.59%)
Mutual labels:  chatbot
Facebook Messenger Bot
Facebook chatbot that I trained to talk like me using Seq2Seq
Stars: ✭ 602 (+3441.18%)
Mutual labels:  chatbot
Me bot
Build a bot that speaks like you!
Stars: ✭ 641 (+3670.59%)
Mutual labels:  chatbot
Program O
PHP MySQL AIML Chatbot - One click installation. Fully loaded admin area to admin your chatbot. Set up multiple chatbots. Foreign language support. XML/JSON responses or just plain HTML. Massive community of users. Twitter Plugins and lots and lots more. Please feel free to fork the DEV branch and contribute. :)
Stars: ✭ 712 (+4088.24%)
Mutual labels:  chatbot
Pymessager
Python API to develop chatbot on Facebook Messenger Platform
Stars: ✭ 580 (+3311.76%)
Mutual labels:  chatbot
Insuranceqa Corpus Zh
🚁 保险行业语料库,聊天机器人
Stars: ✭ 821 (+4729.41%)
Mutual labels:  chatbot
Chinese Chatbot Pytorch Implementation
🍀 Another Chinese chatbot implemented in PyTorch, which is the sub-module of intelligent work order processing robot. 👩‍🔧
Stars: ✭ 576 (+3288.24%)
Mutual labels:  chatbot
Chatito
🎯🗯 Generate datasets for AI chatbots, NLP tasks, named entity recognition or text classification models using a simple DSL!
Stars: ✭ 678 (+3888.24%)
Mutual labels:  chatbot
Nadekobot
Open source, general-purpose Discord chat bot written in C#
Stars: ✭ 892 (+5147.06%)
Mutual labels:  chatbot
Groupme Giphy Bot
A bot that adds the /giphy command to Groupme.
Stars: ✭ 5 (-70.59%)
Mutual labels:  chatbot
Integrations
Connect your App to Multiple Messaging Channels with the W3C Open standard.
Stars: ✭ 721 (+4141.18%)
Mutual labels:  chatbot

Go/Golang package for Viber messaging and chatbot GoDoc

With this package you can use Viber REST API to send and receive messages from Viber platform.

All structs used in package represents the structs identical to Viber REST API. To fully understand Viber messaging platform and this package as well, you should read Viber REST API.

Before using this package you will need Viber public account and your App key which you can find in Edit section of your Viber public account.

Installation

go get github.com/mileusna/viber

Hello World example

package main 

import (
    "fmt"
    "log"

    "github.com/mileusna/viber"
)

func main() {
    v := viber.New("YOUR-APP-KEY-FROM-VIBER", "MyPage", "https://mysite.com/img/avatar.jpg")

    // you really need this only once, remove after you set the webhook
    v.SetWebhook("https://mysite.com/viber/webhook/", nil)

    userID := "Goxxuipn9xKKRqkFOOwKnw==" // fake user ID, use the real one

    // send text message
    token, err := v.SendTextMessage(userID, "Hello, World!")
    if err != nil {
        log.Println("Viber error:", err)
        return
    }
    fmt.Println("Message sent, message token:", token)
}

At the begining you neew to declare your viber struct with you app key. Sender is default sender which will be used as default for sending all messages to the users and public account. But, for each message you can specify different sender if you like.

v := viber.New("YOUR-APP-KEY-FROM-VIBER", "MyPage", "https://mysite.com/img/avatar.jpg")

Read more about SetWebhook in following chapter.

After that, you can send different kind of messages to the user.

Here you can read how to handle message receiving.

Webhook

To be able to receive messages and notifications from Viber you have to specify your webhook. Webhook is the URL where Viber will send you all messages and notification. You only have to do this once in a lifetime. URL of webhook have to be online in moment you call SetWebhook since Viber will send http request to webhook URL expecting HTTP status code 200. For more info visit Viber documentation on Webhooks.

// if eventTypes is nil, all callbacks will be set to webhook
// if eventTypes is empty []string mandatory callbacks will be set
// Mandatory callbacks: "message", "subscribed", "unsubscribed"
// All possible callbacks: "message", "subscribed",  "unsubscribed", "delivered", "seen", "failed", "conversation_started"
v.SetWebhook("https://mysite.com/viber/webhook/", nil)

Messaging

You can send message in different ways. The easiest way is to use shortcut functions like SendTextMessage or SendURLMessage:

v.SendTextMessage(userID, "Hello, World!")

v.SendURLMessage(userID, "Visit my site", "http://mysite.com/")

v.SendPictureMessage(userID, "Take a look at this photo", "http://mysite.com/photo.jpg")

This function will send messages to userID (you will get userID when you receive message from user) using default sender specified in declaration.

You can create individual message, change some settings and then send it using SendMessage

// create message, change the sender for this message and then send id
m := v.NewTextMessage("Hello, world!")
m.Sender = viber.Sender{
    Name:   "SomeOtherName",
    Avatar: "https://mysite.com/img/other_avatar.jpg",
}
v.SendMessage(userID, m)

Carousel messages

Documentation coming soon.

Send Messages to Public Account

In previous examples you send messages directly to the user subscribed to your public account. If you want to send message to the Public Account which will be seen by all PA followers, use te SendPublicMessage function.

// adminID is the ID of PA administrator
m := v.NewTextMessage("Hello to everyone")
v.SendPublicMessage(adminID, m)

imgMsg := v.NewImageMessage("Photo for everyone", "http://mysite.com/photo.jpg")
v.SendPublicMessage(adminID, imgMsg)

Account info

In previous example you have to use ID of administrator of Public account. To obtain Public Acount info and the list of administrators, use the AccountInfo function.

a, err := v.AccountInfo()
if err != nil {
    log.Println("AccountInfo Viber error:", err)
    return
}

// print all admministrators
for _, m := range a.Members {
    fmt.Println(m.ID, m.Name, m.Role)
}

User details

When receiving message from user, or when user starts the conversation, you will receive some bacis user info. To obtain full user details use the UserDetails function.

u, err := v.UserDetails(userID)
if err != nil {
    log.Println("User details viber error:", err)
    return
}

fmt.Println("Details:", u.Name, u.Avatar, u.Country, u.Language, u.DeviceType, u.PrimaryDeviceOs)

Receiving messages / Callbacks

To receive messages and other callbacks, you have to run you viber app on webhook URL you specified using SetWebhook. You can easily manage all Viber callbacks (Message, Subscribed, Unsubscribed, Delivered, Seen, Failed) using this package by specifying your own functions which will be called on event.

package main

import (
    "fmt"
    "log"
    "net/http"
    "time"

    "github.com/mileusna/viber"
)

func main() {
    v := &viber.Viber{
        AppKey: "YOUR-APP-KEY-FROM-VIBER",
        Sender: viber.Sender{
            Name:   "MyPage",
            Avatar: "https://mysite.com/img/avatar.jpg",
        },
        Message:   myMsgReceivedFunc,  // your function for handling messages
        Delivered: myDeliveredFunc,    // your function for delivery report
    }
    v.Seen = mySeenFunc   // or assign events after declaration
    
    // this have to be your webhook, pass it your viber app as http handler
    http.Handle("/viber/webhook/", v)
    http.ListenAndServe(":80", nil)    
}

// myMsgReceivedFunc will be called everytime when user send us a message
func myMsgReceivedFunc(v *viber.Viber, u viber.User, m viber.Message, token uint64, t time.Time) {
    switch m.(type) {

    case *viber.TextMessage:
        v.SendTextMessage(u.ID, "Thank you for your message")
        txt := m.(*viber.TextMessage).Text
        v.SendTextMessage(u.ID, "This is the text you have sent to me "+txt)

    case *viber.URLMessage:
        url := m.(*viber.URLMessage).Media
        v.SendTextMessage(u.ID, "You have sent me an interesting link "+url)

    case *viber.PictureMessage:
        v.SendTextMessage(u.ID, "Nice pic!")

    }
}

func myDeliveredFunc(v *viber.Viber, userID string, token uint64, t time.Time) {
    log.Println("Message ID", token, "delivered to user ID", userID)
}

func mySeenFunc(v *viber.Viber, userID string, token uint64, t time.Time) {
    log.Println("Message ID", token, "seen by user ID", userID)
}


// All events that you can assign your function, declarations must match
// ConversationStarted func(v *Viber, u User, conversationType, context string, subscribed bool, token uint64, t time.Time) Message
// Message             func(v *Viber, u User, m Message, token uint64, t time.Time)
// Subscribed          func(v *Viber, u User, token uint64, t time.Time)
// Unsubscribed        func(v *Viber, userID string, token uint64, t time.Time)
// Delivered           func(v *Viber, userID string, token uint64, t time.Time)
// Seen                func(v *Viber, userID string, token uint64, t time.Time)
// Failed              func(v *Viber, userID string, token uint64, descr string, t time.Time) 
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].