firmafon

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 11 Imported by: 0

README

go-firmafon

Go library for accessing the Firmafon API.

Build Status Test suite Status Go Report Card codecov

Installation

go get github.com/steffen25/go-firmafon

Usage

import "github.com/steffen25/go-firmafon"

Construct a new Firmafon client using an access token which you can generate here Generate Token

client := firmafon.NewClient("token")
List all employees
client := firmafon.NewClient("token")

// list all employees for your organization
users, _, err := client.Employees.All()
if err != nil {
	// Handle error
}

// print each employee's name
for _, u := range users {
	fmt.Println(u.Name)
}
Phone calls

Get a list of calls to or from one or more numbers.

Get all
client := firmafon.NewClient("token")

// List all calls to and from all numbers
calls, _, err := client.Calls.GetAll()
if err != nil {
	// Handle error
}

// print each call's UUID
for _, c := range calls {
	fmt.Println(c.CallUUID)
}
Get a single call by UUID
client := firmafon.NewClient("token")

// List all calls to and from all numbers
call, _, err := client.Calls.Get("UUID_HERE")
if err != nil {
	// Handle error
}

// print call UUID
fmt.Println(call.CallUUID)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

Types

type AuthError

type AuthError ErrorResponse

func (*AuthError) Error

func (r *AuthError) Error() string

type Call

type Call struct {
	CallUUID    string           `json:"call_uuid"`
	CompanyID   int              `json:"company_id"`
	Endpoint    string           `json:"endpoint"`
	FromNumber  string           `json:"from_number"`
	ToNumber    string           `json:"to_number"`
	FromContact *CallFromContact `json:"from_contact"`
	ToContact   interface{}      `json:"to_contact"`
	Direction   string           `json:"direction"`
	StartedAt   time.Time        `json:"started_at"`
	AnsweredAt  time.Time        `json:"answered_at"`
	AnsweredBy  *CallAnsweredBy  `json:"answered_by"`
	EndedAt     time.Time        `json:"ended_at"`
	Status      string           `json:"status"`
}

type CallAnsweredBy

type CallAnsweredBy struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	Number string `json:"number"`
}

type CallFromContact

type CallFromContact struct {
	ID     int    `json:"id"`
	Number string `json:"number"`
	Name   string `json:"name"`
	Email  string `json:"email"`
}

type CallsListOptions

type CallsListOptions struct {
	Endpoint        string `url:"endpoint"`
	Direction       string `url:"direction"`
	Status          string `url:"status"`
	Number          string `url:"number"`
	Limit           string `url:"limit"`
	StartedAtGtOrEq string `url:"started_at_gt_or_eq"`
	StartedAtLtOrEq string `url:"started_at_lt_or_eq"`
	EndedAtGtOrEq   string `url:"ended_at_gt_or_eq"`
	EndedAtLtOrEq   string `url:"ended_at_lt_or_eq"`
}

type CallsService

type CallsService struct {
	Endpoint string
	// contains filtered or unexported fields
}

func (*CallsService) Get

func (s *CallsService) Get(uuid string) (*Call, *Response, error)

func (*CallsService) GetAll

func (s *CallsService) GetAll(opt *CallsListOptions) ([]*Call, *Response, error)

GetAll returns a slice of calls to or from one or more numbers

type Client

type Client struct {
	AccessToken string

	BaseURL *url.URL

	// Services used for talking to different parts of the Firmafon API
	Employees *EmployeesService
	Calls     *CallsService
	// contains filtered or unexported fields
}

A Client manages communication with the Firmafon API.

func NewClient

func NewClient(token string) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

type Employee

type Employee struct {
	Admin            bool        `json:"admin,omitempty"`
	CloakReception   interface{} `json:"cloak_reception,omitempty"`
	CompanyID        int         `json:"company_id,omitempty"`
	DndTimeoutAt     *time.Time  `json:"dnd_timeout_at,omitempty"`
	DoNotDisturb     bool        `json:"do_not_disturb,omitempty"`
	EmployeeGroupIds []int       `json:"employee_group_ids,omitempty"`
	Features         []string    `json:"features,omitempty"`
	ID               int         `json:"id,omitempty"`
	LivePresence     string      `json:"live_presence,omitempty"`
	Name             string      `json:"name,omitempty"`
	Number           string      `json:"number,omitempty"`
	SpeedDial        *SpeedDial  `json:"speed_dial,omitempty"`
}

type EmployeesService

type EmployeesService service

func (*EmployeesService) All

func (s *EmployeesService) All() ([]*Employee, *Response, error)

All returns a slice of all employees

func (*EmployeesService) Authenticated

func (s *EmployeesService) Authenticated() (*Employee, *Response, error)

Authenticated returns the currently authenticated employee.

func (*EmployeesService) GetById

func (s *EmployeesService) GetById(id int) (*Employee, *Response, error)

GetById returns the employee with the specified ID

func (*EmployeesService) SendSMS

func (s *EmployeesService) SendSMS(e *Employee, msg string) (*firmafonSMSResponse, *Response, error)

Send an SMS message to the given employee. The sender will be shown as either the authenticated employee’s number or name. Beware these are cheap, but not free see https://www.firmafon.dk/prisliste This feature is not available for companies in trial.

func (*EmployeesService) Update

func (s *EmployeesService) Update(e *Employee) (*Employee, *Response, error)

Update Updates an employee by ID. Only administrators can update other employees.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Status   string `json:"status"`  // error message returned from api
	Message  string `json:"message"` // error message returned from api
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Response

type Response struct {
	*http.Response
}

type SpeedDial

type SpeedDial struct {
	Digit int `json:"digit,omitempty"`
}

Jump to

Keyboard shortcuts

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