tboy

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 14 Imported by: 1

README

Test Boy

TBoy是一个测试框架,模拟FreeSWITCH的行为。

核心模拟一些基本的操作,可以直接使用,也可以根据需要进行扩展。参见ecc/ttboy的扩展用法。

考虑呼叫的各种情况,秒接,30秒接,不接,拒接,等等,都可以扩展tboy。我们吸收了多种情况下的tboy,在测试的时候选个合适的boy,给定适当的参数配置就可以测试多种情况,而不用自己拿着3个话机互相打。

点对点呼叫

node_uuid    = "simple-test.simple"
domain       = "test.test"
  • 秒接

    boy := tboy.NewSimple(node_uuid, domain, tboy.OptionPeerAnswer(true))
    
  • 30秒接

    boy := tboy.NewSimple(node_uuid, domain, tboy.OptionPeerAnswer(true), tboy.OptionPeerWait(30))
    
  • 拒接

    boy := tboy.NewSimple(node_uuid, domain, tboy.OptionPeerReject(true))
    

队列呼叫

  • 未分配坐席

    boy := tboy.NewACD(node_uuid, domain, tboy.OptionAcdAssign(false))
    
  • 分配坐席未接

    boy := tboy.NewACD(node_uuid, domain, tboy.OptionAcdAssign(true), tboy.OptionPeerAnswer(false))
    
  • 分配坐席接听

boy := tboy.NewACD(node_uuid, domain, tboy.OptionAcdAssign(true), tboy.OptionPeerAnswer(true))

使用方式

1,预先启动一个nats服务器

2,根据呼叫测试情况,启用一个呼叫boy

node_uuid    = "simple-test.simple"
node_topic   = "simple-test"
domain       = "test.test"
boy := tboy.NewSimple(node_uuid, domain, tboy.OptionPeerAnswer(true))
err := ctrl.Init(boy, true, natsAddress)
	fmt.Println(err)

ctrl.Subscribe("cn.xswitch.node.test", boy.EventCallback, "node")
ctrl.Subscribe("cn.xswitch.node.test."+node_topic, boy.EventCallback, "node")
ctrl.Subscribe("cn.xswitch.node.test."+node_uuid, boy.EventCallback, "")

3,调用dial接口测试呼叫流程

nodejs调用单个方法

var rpc = {
	jsonrpc: "2.0",
	method: "XNode.Play",
	id: id,
	params: {
		ctrl_uuid: 'test-nodejs-controller',
		data: file
		uuid: uuid
	}
}
service = "cn.xswitch.node.test"
const msg = JSON.stringify(rpc);
console.log("sending " + msg);
nc.subscribe('cn.xswitch.ctrl.test-nodejs-controller',function (msg, reply, subject, sid) {...});
nc.request(service, msg, { max: 1, timeout: 5000 }, (msg) => {...});

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Channels map[string]*FakeChannel

Functions

func CacheChannel

func CacheChannel(uuid string, channel *FakeChannel)

Types

type App

type App struct {
	App  string `json:"app,omitempty"`
	Data string `json:"data,omitempty"`
}

App .

type CallDetailRecord

type CallDetailRecord struct {
	UUID                        string `json:"uuid" validate:"required"`       // 话单UUID
	Domain                      string `json:"xcc_domain"`                     // 域
	Mark                        string `json:"xcc_mark"`                       // 号码方向
	UID                         string `json:"xcc_uid"`                        // 用户UID
	Context                     string `json:"context"`                        // context
	Billsec                     int    `json:"billsec,string"`                 // 通话时长
	CallerIDName                string `json:"caller_id_name"`                 // 主叫名称
	CallerIDNumber              string `json:"caller_id_number"`               // 主叫号码
	DestinationNumber           string `json:"destination_number"`             // 被叫号码
	OriginCidNumber             string `json:"xcc_origin_cid_number"`          // 原始主叫号码
	OriginDestNumber            string `json:"xcc_origin_dest_number"`         // 原始被叫号码
	OriginOutboundCidNumber     string `json:"xcc_origin_outbound_cid_number"` // 原始外显号码
	StationType                 string `json:"xcc_stationtype"`                // SIP | PSTN
	Direction                   string `json:"direction"`                      // 逻辑方向
	Duration                    int    `json:"duration,string"`                // 花费时长
	HangupCause                 string `json:"hangup_cause"`                   // 挂机原因
	PeerUUID                    string `json:"peer_uuid"`                      // 对端UUID
	SipToHost                   string `json:"sip_to_host"`                    //
	SipFromHost                 string `json:"sip_from_host"`                  //
	SipDisplay                  string `json:"sip_from_display"`               //
	SipNetworkAddr              string `json:"sip_local_network_addr"`         //
	SipNetworkPort              int    `json:"sip_network_port,string"`        //
	SipHangupDisposition        string `json:"sip_hangup_disposition,omitempty"`
	SofiaProfileName            string `json:"sofia_profile_name"`               // default 分机号码, public 外线号码, interconnect 转移
	SofiaProfileURL             string `json:"sofia_profile_url"`                //
	StartStamp                  string `json:"start_stamp"`                      // 开始时间
	AnswerStamp                 string `json:"answer_stamp"`                     // 接听时间
	EndStamp                    string `json:"end_stamp"`                        // 结束时间
	Leg                         string `json:"leg"`                              //
	ServingSide                 string `json:"cc_side"`                          //
	ServingAgentUUID            string `json:"cc_agent"`                         // 坐席UUID
	ServingAgentName            string `json:"cc_agent_name"`                    // 坐席名称
	ServingAgentScore           int    `json:"cc_agent_rating_score,string"`     // 评分
	ServingAgentSession         string `json:"cc_agent_session_uuid"`            //
	ServingAgentEmployeeNumber  string `json:"cc_agent_employee_number"`         // 工号
	ServingQueueUUID            string `json:"cc_queue"`                         // 队列UUID
	ServingQueueName            string `json:"cc_queue_name"`                    // 队列名称
	ServingQueueJoinedEpoch     int64  `json:"cc_queue_joined_epoch,string"`     // 加入队列时间
	ServingQueueAnsweredEpoch   int64  `json:"cc_queue_answered_epoch,string"`   // 坐席应答时间
	ServingQueueTerminatedEpoch int64  `json:"cc_queue_terminated_epoch,string"` // 坐席挂机时间
	ServingContact              string `json:"cc_contact"`                       //
	MemberUUID                  string `json:"cc_member_uuid"`                   // 成员UUID
	MemberSession               string `json:"cc_member_session_uuid"`           //
	Session                     string `json:"xcc_session"`                      // session
}

CallDetailRecord 话单详情

type Dialplan

type Dialplan struct {
	UID                string `json:"xcc_uid,omitempty"`
	UUID               string `json:"uuid,omitempty"`
	NodeUUID           string `json:"node_uuid,omitempty"`
	Domain             string `json:"xcc_domain,omitempty"`
	Context            string `json:"context,omitempty"`
	FromHost           string `json:"sip_from_host,omitempty"`
	ToHost             string `json:"sip_to_host,omitempty"`
	Network            string `json:"sip_network,omitempty"`
	Date               string `json:"date_local,omitempty"`
	Direction          string `json:"caller_direction,omitempty"`
	CallerName         string `json:"caller_name,omitempty"`
	CallerNumber       string `json:"caller_number,omitempty"`
	DestinationNumber  string `json:"destination_number,omitempty"`
	RoutingTag         string `json:"xcc_routing_tag,omitempty"`
	RouteUuid          string `json:"xcc_route_uuid,omitempty"`
	RedlistExecChecked string `json:"xcc_redlist_exec_checked,omitempty"` // 判断是否已经执行过红名单

	OriginCidNumber  string // 内部转发带不过来,需从 session 中取
	OriginDestNumber string // 内部转发带不过来,需从 session 中取

	Session string `json:"xcc_session,omitempty"`
}

Dialplan .

type FakeChannel

type FakeChannel struct {
	CtrlUuid string
	PeerUuid string
	Lock     sync.RWMutex
	Data     *xctrl.ChannelEvent
	Context  context.Context
	Cancel   context.CancelFunc
}

type OptionFn

type OptionFn func(*Options)

func OptionAcdAssign

func OptionAcdAssign(assgin bool) OptionFn

func OptionActualPlay

func OptionActualPlay(play bool) OptionFn

func OptionPeerAnswer

func OptionPeerAnswer(answer bool) OptionFn

func OptionPeerReject

func OptionPeerReject(reject bool) OptionFn

func OptionPeerWait

func OptionPeerWait(wait int) OptionFn

type Options

type Options struct {
	PeerWait   int
	PeerAnswer bool
	PeerReject bool
	AcdAssign  bool
	ActualPlay bool
}

type RequestParam

type RequestParam struct {
	UUID     string `json:"uuid"`
	NodeIP   string `json:"node_ip"`
	NodeUUID string `json:"node_uuid"`

	CDR *CallDetailRecord `json:"cdr" validate:"required"`
}

RequestParam .

type TBoy

type TBoy struct {
	NodeUUID string
	Domain   string
	*Options
}

TBoy .

func (*TBoy) Accept

func (boy *TBoy) Accept(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Answer

func (boy *TBoy) Answer(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Bridge

func (boy *TBoy) Bridge(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) ChannelBridge

func (boy *TBoy) ChannelBridge(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Dial

func (boy *TBoy) Dial(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) DialError

func (boy *TBoy) DialError(ctx context.Context, msg *ctrl.Message, reply string, code int32)

func (*TBoy) Error

func (boy *TBoy) Error(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Event

func (boy *TBoy) Event(msg *ctrl.Message, natsEvent nats.Event)

func (*TBoy) GetVar

func (boy *TBoy) GetVar(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Hangup

func (boy *TBoy) Hangup(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Init

func (boy *TBoy) Init()

func (*TBoy) NativeAPI

func (boy *TBoy) NativeAPI(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) NativeAPIStatus

func (boy *TBoy) NativeAPIStatus(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) NativeJSAPI

func (boy *TBoy) NativeJSAPI(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) NativeJSAPIStatus

func (boy *TBoy) NativeJSAPIStatus(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) OK

func (boy *TBoy) OK(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) ReadDTMF

func (boy *TBoy) ReadDTMF(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Record

func (boy *TBoy) Record(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) SetDomain

func (boy *TBoy) SetDomain(domain string)

func (*TBoy) SetUUID

func (boy *TBoy) SetUUID(uuid string)

func (*TBoy) SetVar

func (boy *TBoy) SetVar(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoy) Stop

func (boy *TBoy) Stop(ctx context.Context, msg *ctrl.Message, reply string)

type TBoyACD

type TBoyACD struct {
	*TBoy
}

func NewACD

func NewACD(node_uuid string, domain string, fn ...OptionFn) *TBoyACD

NewTBoy .

func (*TBoyACD) AddChannel

func (boy *TBoyACD) AddChannel(key string, channel *FakeChannel)

func (*TBoyACD) Dial

func (boy *TBoyACD) Dial(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoyACD) Event

func (boy *TBoyACD) Event(msg *ctrl.Message, natsEvent nats.Event)

func (*TBoyACD) Play

func (boy *TBoyACD) Play(ctx context.Context, msg *ctrl.Message, reply string)

func (*TBoyACD) Transfer

func (boy *TBoyACD) Transfer(ctx context.Context, msg *ctrl.Message, reply string)

type TBoySimple

type TBoySimple struct {
	*TBoy
}

func NewSimple

func NewSimple(node_uuid string, domain string, fn ...OptionFn) *TBoySimple

NewTBoy .

func (*TBoySimple) AddChannel

func (boy *TBoySimple) AddChannel(key string, channel *FakeChannel)

func (*TBoySimple) ChannelEvent

func (boy *TBoySimple) ChannelEvent(ctx context.Context, channel *ctrl.Channel)

we don't use this method in node side

Jump to

Keyboard shortcuts

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