zammadbridge

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: EUPL-1.2 Imports: 13 Imported by: 0

README

3cx-zammad-bridge

Monitors calls in 3CX and communicates this to Zammad accordingly.

Requirements

  • Linux x86_64

Installation

  • Download the latest release binary from releases.
    • Copy the binary into /usr/local/bin
  • chmod +x zammadbridge

Configuration

All configuration is done through the config.yaml file, that may appear in these locations:

  • /etc/3cx-zammad-bridge/config.yaml
  • /opt/3cx-zammad-bridge/config.yaml
  • config.yaml (within the working directory of this 3cx bridge process)

The first (found) configuration file will be used. Also refer to the config.yaml.dist file

Bridge:
  poll_interval: 0.5 # decimal; The number of seconds to wait in between polling 3CX for calls

3CX:
    user: "the username of a 3CX admin account"
    pass: "the password of a 3CX admin account"
    host: "the URL of your 3CX server, including https://"
    group: "the name of the 3CX group that should be monitored, for example Support"
    extension_digits: 3 # numeric; How many digits the internal extensions have 
    trunk_digits: 5 # numeric; How many digits the numbers in the trunk have
    queue_extension: 816 # numeric; The number of the queue that the bridge should also listen to
    country_prefix: 49 # numeric; optional; The country dialing prefix to remove from the numbers

Zammad:
    endpoint: https://zammad.example.com/api/v1/cti/secret # The URL of your Zammad server, including the secret in the URL
    log_missed_queue_calls: true # boolean; Whether or not you want to log missed calls to your queue

Running

Run the release binary to run the daemon.

Example supervisord config:

[program:3cx-zammad-bridge]
command = /usr/local/bin/zammadbridge
autostart = true
autorestart = true
startretries = 10
stderr_logfile = /var/log/3cx-zammad-bridge.err.log
stdout_logfile = /var/log/3cx-zammad-bridge.out.log

# Optionally specify a user
user = zammad-bridge

Development

You can build the binary by running make build

Theoretically, this should also run on Windows. You can compile it yourself and report possible issues.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StdErr     = log.New(os.Stderr, "", log.LstdFlags)
	StdOut     = log.New(os.Stdout, "", log.LstdFlags)
	StdVerbose = log.New(io.Discard, "", log.LstdFlags)
)

Functions

func EnableVerboseLogging

func EnableVerboseLogging()

EnableVerboseLogging enables verbose debug statements to Stdout

Types

type CallInformation

type CallInformation struct {
	Id     json.Number `json:"Id"`
	Caller string      `json:"Caller"`
	Callee string      `json:"Callee"`

	// Status has possible values: "Talking", "Transferring", "Routing"
	Status            string `json:"Status"`
	ZammadInitialized bool
	ZammadAnswered    bool

	// Various processed fields
	CallerName     string
	CallerNumber   string
	CalleeName     string
	CalleeNumber   string
	CallUID        string
	Direction      string
	AgentName      string
	AgentNumber    string
	CallFrom       string
	CallTo         string
	ExternalNumber string
}

type Config

type Config struct {
	Bridge struct {
		PollInterval float64 `yaml:"poll_interval"`
	} `yaml:"Bridge"`
	Phone3CX struct {
		User            string `yaml:"user"`
		Pass            string `yaml:"pass"`
		Host            string `yaml:"host"`
		Group           string `yaml:"group"`
		ExtensionDigits int    `yaml:"extension_digits"`
		TrunkDigits     int    `yaml:"trunk_digits"`
		QueueExtension  int    `yaml:"queue_extension"`
		CountryPrefix   string `yaml:"country_prefix"`
	} `yaml:"3CX"`
	Zammad struct {
		Endpoint            string `yaml:"endpoint"`
		LogMissedQueueCalls bool   `yaml:"log_missed_queue_calls"`
	} `yaml:"Zammad"`
}

func LoadConfigFromYaml

func LoadConfigFromYaml(filenames ...string) (*Config, error)

LoadConfigFromYaml tries the provided files for a valid YAML configuration file. It uses the first file it can parse, and only that file.

type GroupListEntryObject

type GroupListEntryObject struct {
	Members struct {
		Selected []struct {
			Number struct {
				Value string `json:"_value"`
			} `json:"Number"`
		} `json:"selected"`
	} `json:"Members"`
}

type GroupListResponseEntry

type GroupListResponseEntry struct {
	Item GroupListEntryObject `json:"Item"`
}

type ZammadApiRequest

type ZammadApiRequest struct {
	Event           string `json:"event"`
	From            string `json:"from"`
	To              string `json:"to"`
	Direction       string `json:"direction"`
	CallId          string `json:"call_id"`
	CallIdDuplicate string `json:"callid"`
	Cause           string `json:"cause,omitempty"`
	AnsweringNumber string `json:"answeringNumber,omitempty"`
	User            string `json:"user,omitempty"`
}

type ZammadBridge

type ZammadBridge struct {
	Config *Config

	Client3CX    http.Client
	ClientZammad http.Client
	// contains filtered or unexported fields
}

func NewZammadBridge

func NewZammadBridge(config *Config) (*ZammadBridge, error)

NewZammadBridge initializes a new client that listens for 3CX calls and forwards to Zammad.

func (*ZammadBridge) Authenticate3CX

func (z *ZammadBridge) Authenticate3CX() error

Authenticate3CX attempts to login to 3CX and retrieve a valid cookie session.

func (*ZammadBridge) Authenticate3CXRetries

func (z *ZammadBridge) Authenticate3CXRetries(maxOffline time.Duration) error

Authenticate3CXRetries retries logging in a while (defined in maxOffline). It waits five seconds for every failed attempt.

func (*ZammadBridge) Fetch3CXCalls

func (z *ZammadBridge) Fetch3CXCalls() ([]CallInformation, error)

func (*ZammadBridge) Fetch3CXGroupId

func (z *ZammadBridge) Fetch3CXGroupId(groupName string) (Id string, Count int, err error)

Fetch3CXGroupId looks for the internal 3CX id for the given group

func (*ZammadBridge) Fetch3CXGroupMembers

func (z *ZammadBridge) Fetch3CXGroupMembers() error

Fetch3CXGroupMembers fetches the details on group members of the 3CX group that we are monitoring.

func (*ZammadBridge) Fetch3CXGroupMembersPage

func (z *ZammadBridge) Fetch3CXGroupMembersPage(objectId string, start int) ([]string, error)

Fetch3CXGroupMembersPage fetches a single page of members of the given group

func (*ZammadBridge) Fetch3CXGroupMembersPageFirst

func (z *ZammadBridge) Fetch3CXGroupMembersPageFirst(groupId string) ([]string, string, error)

Fetch3CXGroupMembersPageFirst fetches the first page of members of the given group

func (*ZammadBridge) Listen

func (z *ZammadBridge) Listen() error

Listen listens for calls and does not return unless something really bad happened.

func (*ZammadBridge) LogIfErr

func (z *ZammadBridge) LogIfErr(err error, context string)

LogIfErr logs to stderr when an error occurs, doing nothing when err is nil.

func (*ZammadBridge) ParsePhoneNumber

func (z *ZammadBridge) ParsePhoneNumber(number string) string

ParsePhoneNumber parses the phone number into a format acceptable to Zammad

func (*ZammadBridge) ProcessCall

func (z *ZammadBridge) ProcessCall(call *CallInformation) error

ProcessCall processes a single ongoing call from 3CX

func (*ZammadBridge) RequestAndProcess

func (z *ZammadBridge) RequestAndProcess() error

RequestAndProcess requests the current calls from 3CX and processes them to Zammad

func (*ZammadBridge) ZammadAnswer

func (z *ZammadBridge) ZammadAnswer(call *CallInformation) error

ZammadAnswer notifies Zammad that the existing call was now answered by an agent.

func (*ZammadBridge) ZammadHangup

func (z *ZammadBridge) ZammadHangup(call *CallInformation, cause string) error

ZammadHangup notifies Zammad that the call was finished with a given cause. Possible values for `cause` are: "cancel", "normalClearing"

func (*ZammadBridge) ZammadNewCall

func (z *ZammadBridge) ZammadNewCall(call *CallInformation) error

ZammadNewCall notifies Zammad that a new call came in. This is the first call required to process calls using Zammad.

func (*ZammadBridge) ZammadPost

func (z *ZammadBridge) ZammadPost(payload ZammadApiRequest) error

ZammadPost makes a POST Request to Zammad with the given payload

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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