⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 call.bas

📁 用VB写的呼叫中心
💻 BAS
字号:
Attribute VB_Name = "Call"
'enum TRUNK_STATE
Const TRK_IDLE = 0
Const TRK_WAIT_CONNECT = 1
Const TRK_PLAY_WELCOM = 2
Const TRK_CHECK_PLAY_WELCOM = 3
Const TRK_PLAY_SELECT = 4
Const TRK_CHECK_PLAY_PASSWORD = 5
Const TRK_CHECK_REC_END = 6
Const TRK_CHECK_PLAY_BYEBYE = 7
Const TRK_CHECK_PLAY_RECORD = 8
Const TRK_CHECK_PLAY_SELECT = 9
Const TRK_CHECK_REC_START = 10
Const TRK_NOTRK = 11

Type TRUNK_STRUCT
    EnCalled As Boolean
    lineState As Long
    Step As Integer       'state of current channel
    userCh As Integer
    pErrMsg As String * 200
    pCallerId As String * 100
    dwTimeOutCounter As Long
End Type

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim nTotATrkCh As Integer
Dim ATrkCh(0 To 100) As TRUNK_STRUCT


Public Sub InitATrunkListCtrl()
    Dim i%
    MainForm.StateGrid.Cols = 5
    MainForm.StateGrid.Row = 0
    
    MainForm.StateGrid.Col = 0
    MainForm.StateGrid.Text = "通道"
    
    MainForm.StateGrid.Col = 1
    MainForm.StateGrid.Text = "模拟通道状态"
    
    MainForm.StateGrid.Col = 2
    MainForm.StateGrid.Text = "主叫号码"
    
    MainForm.StateGrid.Col = 3
    MainForm.StateGrid.Text = "DTMF按键"
    
    MainForm.StateGrid.Col = 4
    MainForm.StateGrid.Text = "出错信息"
    
   
    MainForm.StateGrid.ColWidth(0) = 36 * 12
    MainForm.StateGrid.ColWidth(1) = 85 * 12
    MainForm.StateGrid.ColWidth(2) = 70 * 12
    MainForm.StateGrid.ColWidth(3) = 70 * 12
    MainForm.StateGrid.ColWidth(4) = 200 * 12
     
    MainForm.StateGrid.Rows = 1
    For i% = 0 To nTotATrkCh - 1
    If ATrkCh(i).EnCalled Then MainForm.StateGrid.AddItem (Str(i))
    Next i%
End Sub


Public Sub InitATrunkCh()
    Dim i As Integer
    Dim nDirection As Long
    
    nTotATrkCh = SsmGetMaxCh()
    For i = 0 To nTotATrkCh - 1
        ATrkCh(i).EnCalled = False
        
        If SsmGetAutoCallDirection(i, nDirection) = 1 Then '允许自动接续
            If (nDirection = 0 Or nDirection = 2) Then   'enable call in
                  ATrkCh(i).Step = TRK_IDLE
                  ATrkCh(i).EnCalled = True
            End If
        End If
    Next i
End Sub

Public Function InitCtiSystem() As Boolean
    Dim ErrMsg As String * 200
    
    If SsmStartCti("ShConfig.ini", "ShIndex.ini") <> 0 Then
        '取得初始化出错信息
        SsmGetLastErrMsg ErrMsg
        MsgBox ErrMsg
        InitCtiSystem = False
    End If
    
    InitCtiSystem = True
End Function

Public Sub AppErrorHandler(ch As Integer)
    SsmHangup (ch)
    SsmGetLastErrMsg (ATrkCh(ch).pErrMsg)
    ATrkCh(ch).Step = TRK_IDLE
End Sub

Public Sub UpDateATrunkChListCtrl()
    Dim state As String * 50
    Dim tmpstr As String * 50
    Dim i As Integer
    Dim TheIndex As Integer
    Dim nIndex As Integer
    
    nIndex = 0
    For i = 0 To nTotATrkCh - 1
    If ATrkCh(i).EnCalled Then
        TheIndex = MainForm.StateGrid.Cols * (nIndex + 1) + 1
        Select Case ATrkCh(i).Step
        Case TRK_IDLE:                  state = "空闲"
        Case TRK_WAIT_CONNECT:          state = "等待连接"
        Case TRK_CHECK_PLAY_WELCOM:     state = "播放欢迎词"
        Case TRK_CHECK_PLAY_SELECT:     state = "等待按键选择"
        Case TRK_CHECK_REC_START:       state = "等待录音开始"
        Case TRK_CHECK_REC_END:         state = "录制留言"
        Case TRK_CHECK_PLAY_RECORD:     state = "播放留言"
        Case TRK_CHECK_PLAY_BYEBYE:     state = "播放结束语"
        Case TRK_CHECK_PLAY_PASSWORD:   state = "播放密码"
        Case Else:                      state = "未定义"
        End Select
        If MainForm.StateGrid.TextArray(TheIndex) <> state Then MainForm.StateGrid.TextArray(TheIndex) = state
        
        TheIndex = TheIndex + 1
        tmpstr = MainForm.StateGrid.TextArray(TheIndex) 'display caller ID
        If tmpstr <> ATrkCh(i).pCallerId Then MainForm.StateGrid.TextArray(TheIndex) = ATrkCh(i).pCallerId
                     
        TheIndex = TheIndex + 1
        If ATrkCh(i).Step = TRK_IDLE Then
            state = ""
            tmpstr = MainForm.StateGrid.TextArray(TheIndex)
            If state <> tmpstr Then MainForm.StateGrid.TextArray(TheIndex) = state
        Else
            state = ""
            If SsmGetDtmfStr(i, state) > 0 And IsEmpty(state) = False Then 'receive and display DTMF keys
                tmpstr = MainForm.StateGrid.TextArray(TheIndex)
                If state <> tmpstr Then MainForm.StateGrid.TextArray(TheIndex) = state
            End If
        End If
        
        TheIndex = TheIndex + 1
        tmpstr = MainForm.StateGrid.TextArray(TheIndex)
        'display error messages occured
        If ATrkCh(i).pErrMsg <> tmpstr Then MainForm.StateGrid.TextArray(TheIndex) = ATrkCh(i).pErrMsg
        nIndex = nIndex + 1
    End If
    Next i
End Sub

Public Sub ScanATrunkCh()
    Dim userCh As Integer
    Dim i As Integer
    Dim tmp As Byte
    
    For i = 0 To nTotATrkCh - 1
    If ATrkCh(i).EnCalled Then
        ATrkCh(i).lineState = SsmGetChState(i)
        Select Case ATrkCh(i).Step
        Case TRK_IDLE:
            If ATrkCh(i).lineState = S_CALL_RINGING Then  'ring detected
                SsmPickup (i)
                SsmGetCallerId i, ATrkCh(i).pCallerId
                ATrkCh(i).dwTimeOutCounter = 0
                ATrkCh(i).Step = TRK_WAIT_CONNECT
            Else
                ATrkCh(i).pCallerId = ""
            End If

        Case TRK_WAIT_CONNECT:
            If ATrkCh(i).lineState = S_CALL_TALKING Then
                ATrkCh(i).Step = TRK_PLAY_WELCOM
            End If
        
        Case TRK_PLAY_WELCOM:
            SsmClearFileList (i)
            If SsmAddToFileList(i, "..\..\..\..\DemoVoc\Welcom1.voc", 6, 0, -1) = -1 Or _
                SsmAddToFileList(i, "..\..\..\..\DemoVoc\Welcom2.voc", 6, 0, -1) = -1 Then
                AppErrorHandler (i)
            Else
                If SsmPlayFileList(i) = -1 Then
                    AppErrorHandler (i)
                Else
                    ATrkCh(i).Step = TRK_CHECK_PLAY_WELCOM
                End If
            End If
        
        Case TRK_CHECK_PLAY_WELCOM:
            If (SsmCheckPlay(i) > 0) Then 'end of playing "welcom"
                ATrkCh(i).Step = TRK_PLAY_SELECT
            End If

        Case TRK_PLAY_SELECT:
            SsmSetDtmfStopPlay i, 1 'enable DTMF-Stop-Play function
            If (SsmPlayIndexString(i, "Select") = -1) Then
                AppErrorHandler (i)
            Else
                SsmClearRxDtmfBuf (i)
                ATrkCh(i).dwTimeOutCounter = 0
                ATrkCh(i).Step = TRK_CHECK_PLAY_SELECT
            End If
        
        Case TRK_CHECK_PLAY_SELECT:
            If (SsmGetRxDtmfLen(i) >= 1 And SsmCheckPlay(i) > 0) Then
                SsmGet1stDtmf i, tmp
                SsmClearRxDtmfBuf (i)
                Select Case tmp
                Case Asc("1"):           'DTMF=1: record to file "test.voc"
                    If (SsmPlayIndexString(i, "RecPrompt") = -1) Then 'play "press any key to start, and any key again to stop".
                        AppErrorHandler (i)
                    Else
                        ATrkCh(i).dwTimeOutCounter = 0
                        ATrkCh(i).Step = TRK_CHECK_REC_START
                    End If

                Case Asc("2"):           'DTMF=2: play recorded file "test.voc"
                    If Dir$("test.voc") <> "" Then
                        If (SsmPlayFile(i, "test.voc", 6, 0, &HFFFFFFFF) = -1) Then
                            AppErrorHandler (i)
                        Else
                            ATrkCh(i).Step = TRK_CHECK_PLAY_RECORD
                        End If
                    Else
                        If (SsmPlayIndexString(i, "FileNotFound") = -1) Then 'play "file not found" message
                            AppErrorHandler (i)
                        Else
                            ATrkCh(i).Step = TRK_CHECK_PLAY_RECORD
                        End If
                    End If

                Case Asc("3"):           'DTMF=3: play user's password,some sample digital
                    SsmSetDtmfStopPlay i, 0 'disable DTMF-Stop-Play function while playing password
                    If (SsmPlayIndexString(i, "YourPasswordIs,1,2,3,4") = -1) Then 'play "your password is 1234".
                        AppErrorHandler (i)
                    Else
                        ATrkCh(i).Step = TRK_CHECK_PLAY_PASSWORD
                    End If
                
                Case Asc("0"):           'DTMF=0:  end of service,play "Byebye"
                     If (SsmPlayIndexString(i, "Byebye") = -1) Then
                        AppErrorHandler (i)
                    Else
                        ATrkCh(i).Step = TRK_CHECK_PLAY_BYEBYE
                    End If
                
                End Select
            ElseIf SsmCheckPlay(i) > 0 Then 'end of playing "Select"
                If ATrkCh(i).lineState = S_CALL_PENDING Then     'check if remote user hangup
                    SsmHangup (i)
                    ATrkCh(i).Step = TRK_IDLE
                Else
                    ATrkCh(i).dwTimeOutCounter = ATrkCh(i).dwTimeOutCounter + 1
                    If ATrkCh(i).dwTimeOutCounter > 100 Then ' wait DTMF key for maximum 10 seconds
                        If SsmPlayIndexString(i, "Byebye") = -1 Then
                            AppErrorHandler (i)
                        Else
                            ATrkCh(i).Step = TRK_CHECK_PLAY_BYEBYE
                        End If
                    End If
                End If
            End If

        Case TRK_CHECK_PLAY_PASSWORD:
            'this channel is not playing index now
            If SsmCheckPlay(i) > 0 Then ATrkCh(i).Step = TRK_PLAY_SELECT

        Case TRK_CHECK_REC_START:
            If SsmGetRxDtmfLen(i) >= 1 Then
                SsmClearRxDtmfBuf (i)
                If SsmRecToFile(i, "test.voc", 6, 0, 80000, 0, 0) = -1 Then 'start from 16000L,maxmium 10 seconds
                    AppErrorHandler (i)
                Else
                    ATrkCh(i).Step = TRK_CHECK_REC_END
                End If
            Else
                ATrkCh(i).dwTimeOutCounter = ATrkCh(i).dwTimeOutCounter + 1
                If ATrkCh(i).dwTimeOutCounter > 300 Then 'wait 15 seconds for DTMF-key
                    If (SsmPlayIndexString(i, "Byebye") = -1) Then
                        AppErrorHandler (i)
                    Else
                        ATrkCh(i).Step = TRK_CHECK_PLAY_BYEBYE
                    End If
                End If
            End If

        Case TRK_CHECK_REC_END:
            If SsmGetRxDtmfLen(i) >= 1 Or SsmChkRecToFile(i) = 0 Then
                SsmStopRecToFile (i)
                ATrkCh(i).Step = TRK_PLAY_SELECT
            End If
            
        Case TRK_CHECK_PLAY_RECORD:
            If SsmCheckPlay(i) > 0 Then ATrkCh(i).Step = TRK_PLAY_SELECT
                

        Case TRK_CHECK_PLAY_BYEBYE:
            If SsmCheckPlay(i) > 0 Then
                SsmHangup (i)
                ATrkCh(i).Step = TRK_IDLE
            End If
        End Select 'end of switch(ATrkCh(i).Step)
    End If
    Next i
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -