Dismiss Notice
We would like to remind you that we’re updating our login process for all 3CX forums whereby you will be able to login with the same credentials you use for the Partner or Customer Portal. Click here to read more.

Change outbound DDI

Discussion in '3CX Phone System - General' started by millsey, May 6, 2015.

Thread Status:
Not open for further replies.
  1. millsey

    millsey New Member

    Joined:
    Dec 21, 2011
    Messages:
    203
    Likes Received:
    0
    Hi

    We have staff calling out as different brands, then sometimes the caller calls back. Is it possible to change the outbound DDI per call, so that the different brands are sent from different DDI numbers? We could do this from the call control API, if only we knew how!

    Ideally we would end up with a web page which lets the user change their outbound DDI just before making the call.

    Thanks
    Millsey
     
  2. craigreilly

    craigreilly Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    3,575
    Likes Received:
    305
    3 options that I can think of...
    1) Setup different SIP accounts that have a different outbound caller id. Then use outbound rules, dial 9, dial 8, etc to use the correct SIP Account with the phone number you need and use the SIP Phone Number field
    2) Setup multiple extensions on the phones and the user picks up the extension they need that has the caller id assigned and setup the trunk to use that outbound number
    3) Custom interface to update the database caller id for the extension. Not recommended and not supported.

    Have wished previously that based simply on outbound rules that I can do this - ie: calls to 911 would always use the same caller id. This is a missing feature for sure.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. millsey

    millsey New Member

    Joined:
    Dec 21, 2011
    Messages:
    203
    Likes Received:
    0
    Craig,

    Having read the Call Control API documentation I am certain we can do this by writing a .NET program to change the OutboundCAllID property of the extension.

    Thanks,

    Millsey
     
  4. millsey

    millsey New Member

    Joined:
    Dec 21, 2011
    Messages:
    203
    Likes Received:
    0
    I have had success in getting this working and for the benefit of the community I post this code. Couple of things - if you are running Visual Studio to build this, you need to copy the 3cxcmp-whatever.dll to the same folder you are building the solution and link to it, and secondly you have to modify the project to compile as x64.

    This code provides a web service you can drop into IIS on a seperate site to the core 3CX stuff. It is written id vb.net NOT c#.

    I simply hope that this helps someone. If you have a coding brain you can review the 3CX API documentation and add other web services in this script which do other stuff. I personally am interested in creatign web services to add and remove an extension from a call queue!

    Millsey

    ----------------------------------------------------------------

    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports TCX.Configuration
    Imports Microsoft.Win32
    Imports System.IO

    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://www.fs.co.uk/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class WebService1
    Inherits System.Web.Services.WebService


    #Region "Private Variables"
    Private pbxconnUser As String
    Private pbxconnPass As String
    Private pbxconnHost As String
    Private pbxconnPort As Integer
    #End Region

    #Region "API Declarations"
    Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    #End Region

    #Region "3CX Settings"

    Private Function configurePhoneSystemObject() As Boolean
    Try
    Dim iniFile = Me.get3CXIniFilename()
    If iniFile Is Nothing Then
    Return False
    Else
    Dim confPort As String = Me.readValueFromINIFile("ConfService", "confPort", iniFile, "5485")
    Dim confUser As String = Me.readValueFromINIFile("ConfService", "confUser", iniFile, "DBServ")
    Dim confPass As String = Me.readValueFromINIFile("ConfService", "confPass", iniFile, "pass")
    Dim port As Int32
    Int32.TryParse(confPort.Trim(), port)
    PhoneSystem.ApplicationName = "TCXWS"
    PhoneSystem.CfgServerPort = port
    PhoneSystem.CfgServerUser = confUser.Trim()
    PhoneSystem.CfgServerPassword = confPass.Trim()
    Return True
    End If
    Catch ex As Exception
    Return "configurePhoneSystemObject()" & vbCrLf & ex.ToString()
    End Try
    End Function

    Private Function readValueFromINIFile(section As String, keyName As String, FileName As String, Optional defaultValue As String = Nothing) As String
    Dim sb As New StringBuilder(500)
    Dim numBytes = GetPrivateProfileString(section, keyName, defaultValue, sb, sb.Capacity, FileName)
    Return sb.ToString()
    End Function

    Private Function get3CXIniFilename() As String
    Dim regKeyAppRoot As RegistryKey = Nothing
    Try
    If IntPtr.Size = 4 Then
    regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\3CX\\PhoneSystem")
    Else
    regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\3CX\\PhoneSystem")
    End If

    Dim _appPath As String = CStr(regKeyAppRoot.GetValue("AppPath"))
    Return CStr(Path.Combine(_appPath, "Bin\3CXPhoneSystem.ini"))
    Catch ex As Exception
    Return "get3CXIniFilename()" & vbCrLf & ex.ToString()
    End Try
    End Function
    #End Region

    <WebMethod()> Public Function ChangeOutgoingDDI(ByVal ExtnToChange As Integer, ByVal OutgoingDDI As String) As String
    ' 080515 BM remove all non numeric chars from the OutGoingDDI
    Dim nonNumericCharacters As New System.Text.RegularExpressions.Regex("[^0-9]")
    Dim numericOnlyOutgoingDDI As String = nonNumericCharacters.Replace(OutgoingDDI, String.Empty)
    configurePhoneSystemObject()
    Try
    Dim exts() As Extension = PhoneSystem.Root.GetExtensions()
    For Each ex As Extension In exts
    If ex.Number = ExtnToChange Then
    ex.OutboundCallerID = numericOnlyOutgoingDDI
    ex.Save()
    Return "OK"
    End If
    Next
    Return "No Such Extension"
    Catch ex As TCX.PBXAPI.PBXIsNotConnected
    Return "FAILED: " & ex.ToString
    End Try
    End Function


    End Class
     
Thread Status:
Not open for further replies.