rbm

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 15 Imported by: 0

README

RCS BUSINESS MESSAGING

Use this library to help you send message to rbm platform with golang

Requirement

This library use golang 1.22.3 or above

Install

Use go get to install this library

go get github.com/faizalwicak/rcsbusinessmessaging

Getting Start

To start using this library you can import this library and call RBMHelper

package main

import (
	"log"
	"path/filepath"

	rbm "github.com/faizalwicak/rcsbusinessmessaging"
)

func main() {
	filename := filepath.Join("temp", "path to credential")
	rbmHelper, err := rbm.GetRBMHelperInstanceFromFile("<agent_id>", filename)
	if err != nil {
		log.Fatalf("fail to get rbm instance %v", err)
	}

	// send single message
	// return rbm id, status message, error
	message := rbm.GetTextMessage("hello", []any{})
	rbmHelper.SendMessage("<msisdn>", message)

	// send multiple message
	// return rbm id, status message, error
	messages := [][]byte{}
	message1 := rbm.GetTextMessage("hello1", []any{})
	messages = append(messages, message1)
	message2 := rbm.GetTextMessage("hello2", []any{})
	messages = append(messages, message2)
	rbmHelper.SendMultipleMessage("<msisdn>", messages)

	// send event
	// return error
	rbmHelper.SendEvent("<msisdn>", "<event>", "<message_id>")

	// check capability
	// return capability code <int>, error
	rbmHelper.CapabilityCheck("<msisdn>")
}

Message

Message Type

// #################################
// generate text message
// #################################
suggestions := []any{}
message = rbm.GetTextMessage("<text>", suggestions)

// #################################
// generate media text
// #################################
rbm.GetMediaMessage("<image / video>", suggestions)

// #################################
// generate standalone card message
// image size: rbm.MEDIA_HEIGHT_MEDIUM, rbm.MEDIA_HEIGHT_TALL
// #################################
message = rbm.GetStandaloneCardMessage("<title>", "<description>", "<image>", "<image size>", suggestions)

// #################################
// generate carousel card message
// minimal sum card number: 3 card
// image size: rbm.MEDIA_HEIGHT_MEDIUM, rbm.MEDIA_HEIGHT_TALL
// card width: rbm.MEDIA_HEIGHT_SMALL, rbm.MEDIA_HEIGHT_MEDIUM
// #################################
cardContents := []rbm.CardContent{}
cardContents = append(cardContents, rbm.GetCardContent("<title>", "<description>", "<image>", "<image size>", suggestions))
cardContents = append(cardContents, rbm.GetCardContent("<title>", "<description>", "<image>", "<image size>", suggestions))
cardContents = append(cardContents, rbm.GetCardContent("<title>", "<description>", "<image>", "<image size>", suggestions))

message = rbm.GetCarouselCardMessage("<card width>", cardContents)
Message Suggestion
// reply text suggestion
rbm.GetReplySuggestion("<text>", "<postback data>")

// open url suggestion
rbm.GetOpenUrlSuggestion("<text>", "<postback data>", "<url>")

// dial number suggestion
rbm.GetDialSuggestion("<text>", "<postback data>", "<phone number>")

// create calender event suggestion
rbm.GetCreateCalendarEventSuggestion("<text>", "<postback data>", "<event title>", "<event description>", "<start time>", "<end time>")

// share location suggestion
rbm.GetShareLocationoSuggestion("<text>", "<postback data>")

// view location suggestion
rbm.GetViewLocationSuggestion("<text>", "<postback data>", "<latitude>", "<longitude>", "<location lable>")

License

Released under the MIT License

Documentation

Index

Constants

View Source
const (
	MEDIA_HEIGHT_TALL   string = "TALL"
	MEDIA_HEIGHT_MEDIUM string = "MEDIUM"
	MEDIA_HEIGHT_SMALL  string = "SMALL"
)

Variables

This section is empty.

Functions

func CapabilityCheck

func CapabilityCheck(token string, msisdn string) (int, error)

func GetAgentConfig

func GetAgentConfig(agent map[string]string) *jwt.Config

func GetAgentFromFile

func GetAgentFromFile(filename string) (map[string]string, error)

func GetAgentTokenFromFile

func GetAgentTokenFromFile(filename string) (*oauth2.Token, error)

func GetCarouselCardMessage

func GetCarouselCardMessage(cardWidth string, cardContent []CardContent) []byte

func GetMediaMessage

func GetMediaMessage(url string, suggestions []RBMSuggestion) []byte

func GetRequestBody

func GetRequestBody(res *http.Response) (string, error)

func GetStandaloneCardMessage

func GetStandaloneCardMessage(title string, description string, imageUrl string, mediaSize string, suggestions []RBMSuggestion) []byte

func GetTextMessage

func GetTextMessage(text string, suggestions []RBMSuggestion) []byte

func JsonToStruct

func JsonToStruct(data []byte) map[string]any

func PrintBodyRequest

func PrintBodyRequest(res *http.Response)

func SendEvent

func SendEvent(token string, msisdn string, event string, messageId string) error

func SendMessage

func SendMessage(agentId string, token string, msisdn string, message []byte) (string, int, error)

func SendMultipleMessage

func SendMultipleMessage(agentId string, token string, msisdn string, messages [][]byte) (string, int, error)

func StructToJson

func StructToJson(data any) []byte

Types

type ActionSuggestion

type ActionSuggestion struct {
	Action RBMSuggestionAction `json:"action"`
}

func GetCreateCalendarEventSuggestion

func GetCreateCalendarEventSuggestion(text string, postbackData string, eventTitle string, eventDescription string, startTime time.Time, endTime time.Time) ActionSuggestion

func GetDialSuggestion

func GetDialSuggestion(text string, postbackData string, phoneNumber string) ActionSuggestion

func GetOpenUrlSuggestion

func GetOpenUrlSuggestion(text string, postbackData string, url string) ActionSuggestion

func GetShareLocationoSuggestion

func GetShareLocationoSuggestion(text string, postbackData string) ActionSuggestion

func GetViewLocationSuggestion

func GetViewLocationSuggestion(text string, postbackData string, lat string, long string, locationLabel string) ActionSuggestion

func (ActionSuggestion) GetSuggestionType added in v0.1.3

func (s ActionSuggestion) GetSuggestionType() string

type ActionSuggestionData

type ActionSuggestionData struct {
	Text         string `json:"text"`
	PostbackData string `json:"postbackData"`
	FallbackUrl  string `json:"fallbackUrl,omitempty"`

	OpenUrlAction             *OpenUrlAction             `json:"openUrlAction,omitempty"`
	DialAction                *DialAction                `json:"dialAction,omitempty"`
	ViewLocatinoAction        *ViewLocatinoAction        `json:"viewLocationAction,omitempty"`
	ShareLocationAction       *ShareLocationAction       `json:"shareLocationAction,omitempty"`
	CreateCalendarEventAction *CreateCalendarEventAction `json:"createCalendarEventAction,omitempty"`
}

func (ActionSuggestionData) GetSuggestionActionType added in v0.1.3

func (a ActionSuggestionData) GetSuggestionActionType() string

type CardContent

type CardContent struct {
	Title       string          `json:"title"`
	Description string          `json:"description"`
	Media       Media           `json:"media"`
	Suggestions []RBMSuggestion `json:"suggestions,omitempty"`
}

func GetCardContent

func GetCardContent(title string, description string, imageUrl string, mediaSize string, suggestions []RBMSuggestion) CardContent

type CarouselCardMessage

type CarouselCardMessage struct {
	CarouselCard CarouselCardMessageData `json:"carouselCard"`
}

func (CarouselCardMessage) GetRichCardType added in v0.1.3

func (s CarouselCardMessage) GetRichCardType() string

type CarouselCardMessageData

type CarouselCardMessageData struct {
	CardWidth    string        `json:"cardWidth"`
	CardContents []CardContent `json:"cardContents"`
}

type ContentInfo

type ContentInfo struct {
	FileUrl      string `json:"fileUrl"`
	ForecRefresh string `json:"forceRefresh"`
}

type ContentMessage

type ContentMessage struct {
	ContentMessage RBMMessage `json:"contentMessage"`
}

func GetTextMessageStruct

func GetTextMessageStruct(text string, suggestions []RBMSuggestion) ContentMessage

type CreateCalendarEventAction

type CreateCalendarEventAction struct {
	StartTime   string `json:"startTime"`
	EndTime     string `json:"endTime"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type DialAction

type DialAction struct {
	PhoneNumber string `json:"phoneNumber"`
}

type LatLong

type LatLong struct {
	Latitude  string `json:"latitude"`
	Longitude string `json:"longitude"`
}

type Media

type Media struct {
	Height      string      `json:"height"`
	ContentInfo ContentInfo `json:"contentInfo"`
}

type MediaMessage

type MediaMessage struct {
	ContentInfo ContentInfo     `json:"contentInfo"`
	Suggestions []RBMSuggestion `json:"suggestions,omitempty"`
}

func (MediaMessage) GetType added in v0.1.3

func (m MediaMessage) GetType() string

type OpenUrlAction

type OpenUrlAction struct {
	Url string `json:"url"`
}

type RBMHelper

type RBMHelper struct {
	// contains filtered or unexported fields
}

func GetRBMHelperInstanceFromFile

func GetRBMHelperInstanceFromFile(agentId string, filename string) (*RBMHelper, error)

func (*RBMHelper) CapabilityCheck

func (h *RBMHelper) CapabilityCheck(msisdn string) (int, error)

func (*RBMHelper) SendEvent

func (h *RBMHelper) SendEvent(msisdn string, event string, messageId string) error

func (*RBMHelper) SendMessage

func (h *RBMHelper) SendMessage(msisdn string, message []byte) (string, int, error)

func (*RBMHelper) SendMultipleMessage

func (h *RBMHelper) SendMultipleMessage(msisdn string, messages [][]byte) (string, int, error)

func (*RBMHelper) SetDebug added in v0.1.3

func (h *RBMHelper) SetDebug(d bool)

type RBMMessage added in v0.1.3

type RBMMessage interface {
	GetType() string
}

type RBMRichCard added in v0.1.3

type RBMRichCard interface {
	GetRichCardType() string
}

type RBMSuggestion added in v0.1.3

type RBMSuggestion interface {
	GetSuggestionType() string
}

type RBMSuggestionAction added in v0.1.3

type RBMSuggestionAction interface {
	GetSuggestionActionType() string
}

type RBMSuggestionReply added in v0.1.3

type RBMSuggestionReply interface {
	GetSuggestionReplyType() string
}

type ReplySuggestion

type ReplySuggestion struct {
	Reply RBMSuggestionReply `json:"reply"`
}

func GetReplySuggestion

func GetReplySuggestion(text string, postbackData string) ReplySuggestion

func (ReplySuggestion) GetSuggestionType added in v0.1.3

func (s ReplySuggestion) GetSuggestionType() string

type RichCardMessage

type RichCardMessage struct {
	RichCard RBMRichCard `json:"richCard"`
}

func (RichCardMessage) GetType added in v0.1.3

func (m RichCardMessage) GetType() string

type ShareLocationAction

type ShareLocationAction struct{}

type StandaloneCardMessage

type StandaloneCardMessage struct {
	StandaloneCard StandaloneCardMessageData `json:"standaloneCard"`
}

func (StandaloneCardMessage) GetRichCardType added in v0.1.3

func (s StandaloneCardMessage) GetRichCardType() string

type StandaloneCardMessageData

type StandaloneCardMessageData struct {
	ThumbnailImageAlignment string      `json:"thumbnailImageAlignment"`
	CardOrientation         string      `json:"cardOrientation"`
	CardContent             CardContent `json:"cardContent"`
}

type SuggestedReply

type SuggestedReply struct {
	Text         string `json:"text"`
	PostbackData string `json:"postbackData"`
}

func (SuggestedReply) GetSuggestionReplyType added in v0.1.3

func (r SuggestedReply) GetSuggestionReplyType() string

type TextMessage

type TextMessage struct {
	Text        string          `json:"text"`
	Suggestions []RBMSuggestion `json:"suggestions,omitempty"`
}

func (TextMessage) GetType added in v0.1.3

func (m TextMessage) GetType() string

type ViewLocatinoAction

type ViewLocatinoAction struct {
	LatLong LatLong `json:"latLong"`
	Label   string  `json:"label"`
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL