contactbuilder

package
v0.0.0-...-eec0033 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package contactbuilder converts astorg types into digium contacts.

This package is experimental and is subject to breaking changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder constructs a slice of digium contact entries.

An empty contact builder is ready for use.

func (*Builder) Add

func (builder *Builder) Add(contacts ...digium.Contact)

Add adds custom contact entries to the builder.

func (*Builder) AddCustomPerson

func (builder *Builder) AddCustomPerson(f PersonFunc, people ...astorg.Person)

AddCustomPerson adds a contact entry for each person to the builder.

The function f will be used to convert people into contacts.

func (*Builder) AddCustomPhoneRole

func (builder *Builder) AddCustomPhoneRole(f PhoneRoleFunc, roles ...astorg.PhoneRole)

AddCustomPhoneRole adds a contact entry for each phone role to the builder.

The function f will be used to convert phone roles into contacts.

func (*Builder) AddPerson

func (builder *Builder) AddPerson(people ...astorg.Person)

AddPerson adds a contact entry for each person to the builder.

The PersonFactory function will be used to convert people into contacts.

func (*Builder) AddPhoneRole

func (builder *Builder) AddPhoneRole(roles ...astorg.PhoneRole)

AddPhoneRole adds a contact entry for each person to the builder.

The PhoneRoleFactory function will be used to convert people into contacts.

func (*Builder) Group

func (builder *Builder) Group(name, id string) digium.ContactGroup

Group returns a compiled group from the builder.

func (*Builder) Reset

func (builder *Builder) Reset()

Reset purges the current contact list from the builder.

type PersonFunc

type PersonFunc func(from *astorg.Person, to *digium.Contact)

PersonFunc is a function that converts people into contacts.

var PersonFactory PersonFunc = func(person *astorg.Person, contact *digium.Contact) {

	contact.ID = person.Username
	contact.Type = "sip"
	contact.FirstName = person.FirstName
	contact.LastName = person.LastName
	contact.Organization = person.Organization
	contact.JobTitle = person.Title
	contact.Location = person.Location
	contact.SubscriptionURI = "auto_hint_" + person.Username
	contact.AccountID = person.Extension

	contact.Actions = append(contact.Actions, digium.ContactAction{
		ID:    "primary",
		Label: "Desk Phone",
		Name:  "Desk Phone",
		Dial:  person.Extension,
	})

	for _, number := range person.ContactNumbers {
		contact.Actions = append(contact.Actions, digium.ContactAction{
			ID:         sanitize(number.Label, "_"),
			Label:      number.Label,
			Name:       number.Label,
			Dial:       number.Dial,
			DialPrefix: number.DialPrefix,
		})
	}
	if person.VoicemailExtension != "" {
		contact.Actions = append(contact.Actions, digium.ContactAction{
			ID:    "send_to_vm",
			Label: "Voicemail",
			Name:  "Voicemail",
			Dial:  person.VoicemailExtension,
			Headers: []digium.ContactHeader{
				digium.ContactHeader{
					Key:   "X-Digium-Call-Feature",
					Value: "feature_send_to_vm",
				},
				digium.ContactHeader{
					Key:   "Diversion",
					Value: `<sip:%_ACCOUNT_USERNAME_%@%_ACCOUNT_SERVER_%:%_ACCOUNT_PORT_%>;reason="send_to_vm"`,
				},
			},
		})
	}
	for _, email := range person.EmailAddresses {
		contact.Emails = append(contact.Emails, digium.ContactEmail{
			Address: email.Address,
			Label:   email.Label,
			Primary: email.Primary,
		})
	}
}

PersonFactory converts people into contacts.

func (PersonFunc) PersonContact

func (f PersonFunc) PersonContact(from *astorg.Person, to *digium.Contact)

PersonContact applies f to from and to.

func (PersonFunc) Then

func (f PersonFunc) Then(series ...PersonFunc) PersonFunc

Then returns a new function that will execute f followed by each member of series.

type PhoneRoleFunc

type PhoneRoleFunc func(from *astorg.PhoneRole, to *digium.Contact)

PhoneRoleFunc is a function that converts phone roles into contacts.

var PhoneRoleFactory PhoneRoleFunc = func(role *astorg.PhoneRole, contact *digium.Contact) {

	contact.ID = role.Username
	contact.Type = "sip"
	contact.FirstName = role.DisplayName
	contact.Location = role.Location
	contact.SubscriptionURI = "auto_hint_" + role.Username
	contact.AccountID = role.Extension
	contact.Actions = append(contact.Actions, digium.ContactAction{
		ID:    "primary",
		Label: "Desk Phone",
		Name:  "Desk Phone",
		Dial:  role.Extension,
	})
}

PhoneRoleFactory converts phone roles into contacts.

func (PhoneRoleFunc) Then

func (f PhoneRoleFunc) Then(series ...PhoneRoleFunc) PhoneRoleFunc

Then returns a new function that will execute f followed by each member of series.

Jump to

Keyboard shortcuts

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