Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyIt committed Jan 4, 2023
0 parents commit cbfc348
Show file tree
Hide file tree
Showing 16 changed files with 1,500 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/
/Godeps/
.idea/
dump/
data/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 pokornyIt.cz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Finesse API

Utilities for work with the Unified Cisco Contact Center agents through Finesse API.

API allows actions per one agent or group of agents.

- get agent status
- login agent
- set agent ready state
- set agent not-ready state
- logout agent

## Limitation
The current version does not use XMPP communication with the Finesse server.
Program tested on version Finesse 12.5.

## How use

For any operation is necessary to create a server structure with an address and port.
It is necessary to register the agents with which the operations will take place on the server.


```go
// import finesse_api library
import (
api "github.com/pokornyIt/finesse-api"
)

// create Finesse server object
server := finesse_api.NewFinesseServer("finesse.server.fqdn", 8435)

// add agents to server
agent := api.NewAgentName("Name1", "Password", "1000")
server.AddAgent(agent)
agent := api.NewAgentName("Name2", "Password", "1001")
server.AddAgent(agent)
agent := api.NewAgentName("Name3", "Password", "1002")
server.AddAgent(agent)

// get status for all defined agent
states, err = server.GetStateAgentsParallel()

// login agent Name2 to system
state := server.LoginAgent("Name2")

// login all agents and set it to ready state
states, err = server.ReadyAgentsParallelWithStatus(true)
```

Program use standard logger library "github.com/sirupsen/logrus".
135 changes: 135 additions & 0 deletions finesse-agent-detail.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package finesse_api

import (
"encoding/xml"
"fmt"
)

// UserDetailResponse Structure holds agent status
// Contains all possible values returned in the get agent state
type UserDetailResponse struct {
XMLName xml.Name `xml:"User"`
Text string `xml:",chardata"`
Dialogs string `xml:"dialogs"`
Extension string `xml:"extension"`
FirstName string `xml:"firstName"`
LastName string `xml:"lastName"`
LoginId string `xml:"loginId"`
LoginName string `xml:"loginName"`
MediaType string `xml:"mediaType"`
ReasonCodeId string `xml:"reasonCodeId"`
ReasonCode struct {
Text string `xml:",chardata"`
Category string `xml:"category"`
URL string `xml:"uri"`
Code string `xml:"code"`
Label string `xml:"label"`
ForAll bool `xml:"forAll"`
Id int `xml:"id"`
} `xml:"ReasonCode"`
Roles struct {
Text string `xml:",chardata"`
Role []string `xml:"role"`
} `xml:"roles"`
Settings struct {
Text string `xml:",chardata"`
WrapUpOnIncoming string `xml:"wrapUpOnIncoming"`
WrapUpOnOutgoing string `xml:"wrapUpOnOutgoing"`
DeviceSelection string `xml:"deviceSelection"`
} `xml:"settings"`
State string `xml:"state"`
StateChangeTime string `xml:"stateChangeTime"`
PendingState string `xml:"pendingState"`
TeamId string `xml:"teamId"`
TeamName string `xml:"teamName"`
SkillTargetId string `xml:"skillTargetId"`
URI string `xml:"uri"`
Teams struct {
Text string `xml:",chardata"`
Team []struct {
Text string `xml:",chardata"`
Id int `xml:"id"`
Name string `xml:"name"`
URI string `xml:"uri"`
} `xml:"Team"`
} `xml:"teams"`
MobileAgent struct {
Text string `xml:",chardata"`
Mode string `xml:"mode"`
DialNumber string `xml:"dialNumber"`
} `xml:"mobileAgent"`
ActiveDeviceId string `xml:"activeDeviceId"`
Devices struct {
Text string `xml:",chardata"`
Device []struct {
Text string `xml:",chardata"`
DeviceId string `xml:"deviceId"`
DeviceType string `xml:"deviceType"`
DeviceTypeName string `xml:"deviceTypeName"`
} `xml:"device"`
} `xml:"devices"`
}

func newUserDetailResponse(data string) (*UserDetailResponse, error) {
var u UserDetailResponse
buffer := []byte(data)
err := xml.Unmarshal(buffer, &u)
if err != nil {
return nil, err
}
return &u, nil
}

// ToString Returns the basic data from the status response as a printable string
func (u *UserDetailResponse) ToString() string {
s := fmt.Sprintf("Dialogs: %s\r\n", u.Dialogs)
s = fmt.Sprintf("%sExtension: %s\r\n", s, u.Extension)
s = fmt.Sprintf("%sFirst Name: %s\r\n", s, u.FirstName)
s = fmt.Sprintf("%sLast Name: %s\r\n", s, u.LastName)
s = fmt.Sprintf("%sLogin ID: %s\r\n", s, u.LoginId)
s = fmt.Sprintf("%sLogin name: %s\r\n", s, u.LoginName)
s = fmt.Sprintf("%sState: %s\r\n", s, u.State)
s = fmt.Sprintf("%sTeam name: %s\r\n", s, u.TeamName)
s = fmt.Sprintf("%sTeam ID: %s\r\n", s, u.TeamId)
s = fmt.Sprintf("%sPending state: %s\r\n", s, u.PendingState)
s = fmt.Sprintf("%sReason code ID: %s\r\n", s, u.ReasonCodeId)
s = fmt.Sprintf("%sRole: %s\n\r", s, u.getRoles())
s = fmt.Sprintf("%sTeams: %s\n\r", s, u.getTeams())

return s
}

// ToStingSimple Returns agent name with current state
func (u *UserDetailResponse) ToStingSimple() string {
return fmt.Sprintf("Agent: %-30s State: %-15s Pending state %s", u.LoginName, u.State, u.PendingState)
}

func (u *UserDetailResponse) getRoles() string {
a := ""
sep := ""
for _, role := range u.Roles.Role {
a = fmt.Sprintf("%s%s%s", a, sep, role)
sep = ", "
}
return a
}

func (u *UserDetailResponse) getTeams() string {
a := ""
sep := ""
for _, team := range u.Teams.Team {
a = fmt.Sprintf("%s%s%s", a, sep, team.Name)
sep = ", "
}
return a
}

// IsLogIn Is agent logged in
func (u *UserDetailResponse) IsLogIn() bool {
return u.State != AgentStateLogout
}

// IsPossibleToLogout Is agent ready for logout
func (u *UserDetailResponse) IsPossibleToLogout() bool {
return u.State == AgentStateNotReady
}
42 changes: 42 additions & 0 deletions finesse-agent-status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package finesse_api

const (
AgentStateLogin string = "LOGIN"
AgentStateLogout = "LOGOUT"
AgentStateReady = "READY"
AgentStateNotReady = "NOT_READY"
AgentStateAvailable = "AVAILABLE"
AgentStateTalking = "TALKING"
AgentStateWorkNotReady = "WORK_NOT_READY"
AgentStateWorkReady = "WORK_READY"
AgentStateReserved = "RESERVED"
AgentStateUnknown = "UNKNOWN"
AgentStateHold = "HOLD"
AgentStateActive = "ACTIVE"
AgentStatePaused = "PAUSED"
AgentStateInterrupted = "INTERRUPTED"
AgentStateNotActive = "NOT_ACTIVE"
)

// AgentStates All valid agent states
var AgentStates = []string{AgentStateLogin, AgentStateLogout, AgentStateReady, AgentStateNotReady, AgentStateAvailable,
AgentStateTalking, AgentStateWorkNotReady, AgentStateWorkReady, AgentStateReserved, AgentStateUnknown, AgentStateHold,
AgentStateActive, AgentStatePaused, AgentStateInterrupted, AgentStateNotActive}

// AgentReadyStates States when agent is ready for work or work
var AgentReadyStates = map[string]string{AgentStateReady: AgentStateReady, AgentStateAvailable: AgentStateAvailable,
AgentStateTalking: AgentStateTalking, AgentStateWorkReady: AgentStateWorkReady, AgentStateReserved: AgentStateReserved,
AgentStateHold: AgentStateHold, AgentStateActive: AgentStateActive}

// AgentLoginStates States when agent is logged in to the system
var AgentLoginStates = map[string]string{AgentStateLogin: AgentStateLogin, AgentStateReady: AgentStateReady,
AgentStateNotReady: AgentStateNotReady, AgentStateAvailable: AgentStateAvailable, AgentStateTalking: AgentStateTalking,
AgentStateWorkNotReady: AgentStateWorkNotReady, AgentStateWorkReady: AgentStateWorkReady, AgentStateReserved: AgentStateReserved,
AgentStateHold: AgentStateHold, AgentStateActive: AgentStateActive, AgentStatePaused: AgentStatePaused,
AgentStateInterrupted: AgentStateInterrupted, AgentStateNotActive: AgentStateNotActive}

// AgentNotReadyStates States when agent is not-ready
var AgentNotReadyStates = map[string]string{AgentStateNotReady: AgentStateNotReady, AgentStateWorkNotReady: AgentStateWorkNotReady}

// AgentLogoutState States when agent is not logged in to the system
var AgentLogoutState = map[string]string{AgentStateLogout: AgentStateLogout, AgentStateUnknown: AgentStateUnknown}
41 changes: 41 additions & 0 deletions finesse-agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package finesse_api

import (
"encoding/xml"
)

// FinesseAgent Login information of agent
type FinesseAgent struct {
LoginName string // login name
LoginId string // login ID
Password string // password
Line string // phone line
}

// NewAgent Creating agent login data
func NewAgent(id string, name string, pwd string, line string) *FinesseAgent {
return &FinesseAgent{
LoginId: id,
LoginName: name,
Password: pwd,
Line: line,
}
}

// NewAgentName Creating agent login data without "agent Id" necessary for requests
func NewAgentName(name string, pwd string, line string) *FinesseAgent {
return NewAgent("", name, pwd, line)
}

func (a *FinesseAgent) loginRequest() *userLoginRequest {
return &userLoginRequest{
XMLName: xml.Name{},
Text: "",
State: AgentStateLogin,
Extension: a.Line,
}
}

func (a *FinesseAgent) setAgentId(newId string) {
a.LoginId = newId
}
Loading

0 comments on commit cbfc348

Please sign in to comment.