Documentation
¶
Index ¶
- type API3CX
- type CallControlResponse
- type CallControlResponseEntry
- type CallInformation
- type CallParticipant
- type Client3CXPost20
- type Client3CXPre20
- type Config
- type GroupListEntryObject
- type GroupListResponseEntry
- type WebsocketEventType
- type WebsocketResponse
- type ZammadApiRequest
- type ZammadBridge
- func (z *ZammadBridge) Listen() error
- func (z *ZammadBridge) LogIfErr(err error, context string)
- func (z *ZammadBridge) ParsePhoneNumber(number string) string
- func (z *ZammadBridge) ProcessCall(call *CallInformation) error
- func (z *ZammadBridge) RequestAndProcess() error
- func (z *ZammadBridge) ZammadAnswer(call *CallInformation) error
- func (z *ZammadBridge) ZammadHangup(call *CallInformation, cause string) error
- func (z *ZammadBridge) ZammadNewCall(call *CallInformation) error
- func (z *ZammadBridge) ZammadPost(payload ZammadApiRequest) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API3CX ¶ added in v0.7.0
type API3CX interface {
// AuthenticateRetry authenticates the client and retries in case of offline status
// maxOffline specifies the maximum duration to wait for the client to come online.
AuthenticateRetry(maxOffline time.Duration) error
// FetchCalls retrieves information about current calls from the 3CX API.
// It returns a slice of CallInformation structs and an error if the API call fails.
FetchCalls() ([]CallInformation, error)
// IsExtension checks if a given phone number is a valid extension that is being monitored.
IsExtension(number string) bool
}
API3CX abstracts away the differences in API versions from before v20 and after v20 of 3CX.
func Create3CXClient ¶ added in v0.7.0
Create3CXClient creates a 3CX client based on the provided configuration.
It first attempts to create a v20 client, and if it fails with an HTTP 404 error, it falls back to creating a pre-v20 client. The function returns an API3CX interface and an error if the client creation fails.
The client is created with a cookiejar and authenticated using the AuthenticateRetry method, which waits for the client to come online for a maximum duration of two minutes.
type CallControlResponse ¶ added in v0.7.0
type CallControlResponse []CallControlResponseEntry
type CallControlResponseEntry ¶ added in v0.7.0
type CallControlResponseEntry struct {
DN string `json:"dn"`
Participants []CallParticipant `json:"participants"`
}
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
// Timestamps
LastChangeStatus time.Time `json:"LastChangeStatus"`
EstablishedAt time.Time `json:"EstablishedAt"`
// 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 CallParticipant ¶ added in v0.7.0
type CallParticipant struct {
ID int `json:"id"`
// Status is the status of the call. Possible values include: "Dialing", "Ringing", "Connected"
Status string `json:"status"`
// DN is the extension number of the participant.
DN string `json:"dn"`
// PartyCallerName is the name of the caller or callee. Can be empty.
PartyCallerName string `json:"party_caller_name"`
// PartyDN is the extension number of the caller. E.g. 10007
PartyDN string `json:"party_dn"`
// PartyCallerID is the caller ID of the caller. E.g. 0123456789
PartyCallerID string `json:"party_caller_id"`
// PartyDID is the DID of the caller. Can be empty.
PartyDID string `json:"party_did"`
// CallID is the unique ID of the call.
CallID int `json:"callid"`
}
type Client3CXPost20 ¶ added in v0.7.0
type Client3CXPost20 struct {
Config *Config
// contains filtered or unexported fields
}
func (*Client3CXPost20) Authenticate ¶ added in v0.7.0
func (z *Client3CXPost20) Authenticate() error
Authenticate attempts to login to 3CX and stores a token for future API calls. It then loads all extensions we are configured to monitor.
func (*Client3CXPost20) AuthenticateRetry ¶ added in v0.7.0
func (z *Client3CXPost20) AuthenticateRetry(maxOffline time.Duration) error
AuthenticateRetry retries logging in a while (defined in maxOffline). It waits five seconds for every failed attempt.
func (*Client3CXPost20) FetchCalls ¶ added in v0.7.0
func (z *Client3CXPost20) FetchCalls() ([]CallInformation, error)
func (*Client3CXPost20) IsExtension ¶ added in v0.7.0
func (z *Client3CXPost20) IsExtension(_ string) bool
type Client3CXPre20 ¶ added in v0.7.0
type Client3CXPre20 struct {
Config *Config
// contains filtered or unexported fields
}
func (*Client3CXPre20) Authenticate ¶ added in v0.7.0
func (z *Client3CXPre20) Authenticate() error
Authenticate attempts to login to 3CX and retrieve a valid cookie session.
func (*Client3CXPre20) AuthenticateRetry ¶ added in v0.7.0
func (z *Client3CXPre20) AuthenticateRetry(maxOffline time.Duration) error
AuthenticateRetry retries logging in a while (defined in maxOffline). It waits five seconds for every failed attempt.
func (*Client3CXPre20) FetchCalls ¶ added in v0.7.0
func (z *Client3CXPre20) FetchCalls() ([]CallInformation, error)
func (*Client3CXPre20) IsExtension ¶ added in v0.7.0
func (z *Client3CXPre20) IsExtension(number string) bool
type Config ¶
type Config struct {
Bridge struct {
PollInterval float64 `yaml:"poll_interval"`
} `yaml:"Bridge"`
Phone3CX struct {
User string `yaml:"user"`
Pass string `yaml:"pass"`
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
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 ¶
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 WebsocketEventType ¶ added in v0.7.0
type WebsocketEventType int
const ( WebsocketEventTypeUpsert WebsocketEventType = 0 WebsocketEventTypeDelete WebsocketEventType = 1 WebsocketEventTypeDTMFstring WebsocketEventType = 2 WebsocketEventTypeResponse WebsocketEventType = 4 )
type WebsocketResponse ¶ added in v0.7.0
type WebsocketResponse struct {
Sequence int `json:"sequence"`
Event struct {
EventType WebsocketEventType `json:"event_type"`
Entity string `json:"entity"`
AttachedData *json.RawMessage `json:"attached_data"`
} `json:"event"`
}
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 API3CX
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) 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