Can't get Informations Of Caller

Hello! Im using Aster.NET to get the informations of the caller ID.

The connection is working and it detects when i receive a call. The problem is that when i receive a call i can’t get the information about it.

And also im getting erros in the attributes.trygetvalue.

Some screenshots here:
This is what happens when i receive a call… I just cant get the phone number or name of the caller.
image

This is my code:

    Private Sub Monitoring_NewState(ByVal sender As Object, ByVal e As NewStateEvent)
        Dim state As String = e.State
        Dim callerID As String = e.CallerIdNum
        Dim callerNAME As String = e.CallerIdName
        Console.WriteLine("Phone Number: ", callerID)
        Console.Write("Name: ", callerNAME)

        If (state = "Ringing") Or (e.ChannelState = "5") Then
            Console.WriteLine("Getting call...")
            Dim connectedLineNum As String
            Dim connectedLineName As String
            'Dim attributes As Dictionary(Of String, String) = e.Attributes
            'attributes.TryGetValue("connectedlinenum", connectedLineNum)
            'attributes.TryGetValue("connectedlinename", connectedLineName)
        ElseIf (state = "Ring") Or (e.ChannelState = "4") Then
            Console.WriteLine("Getting call...")
        ElseIf (state = "Up") Or (e.ChannelState = "6") Then
            Dim connectedLineNum As String
            Dim connectedLineName As String
            'Dim attributes As Dictionary(Of String, String) = e.Attributes
            'attributes.TryGetValue("connectedlinenum", connectedLineNum)
            'attributes.TryGetValue("connectedlinename", connectedLineName)
        End If
    End Sub

AsterNET is third party software, and is little used, compared with, say, the PHP AMI class libraries, so it is unlikely that any regular here is familiar with it.

Are you sure that you didn’t mean CALLERID(num) and CALLERID(name). Note that case is important.

Unless you have copied ${CONNECTEDLINE(number)} to connectedlinenum, in your dialplan, the variable connectedlinenum will be unset.

Hello, sorry but im not programming in PHP. It’s in .NET

The chances of finding someone who monitors the forum and uses .NET is rather low, but all but the first sentence applies to any class library.

i could not understand what you said… I cant figured it out, why i cant get the caller phone number…

Because you are reading a variable that doesn’t exist (or at least you have not provided the part of your code that would bring it into existence).

Also, you seem to be using a roundabout way of accessing it (and I’m not sure that would work even with the right function name and parameters).

alright, i will put all the code, please help me if you can…

Public Class connection

    Public manager As ManagerConnection = Nothing

    Private Sub Guna2Button1_Click(sender As Object, e As EventArgs) Handles btnconnect.Click
        Dim address As String = txthost.Text
        Dim port As Integer = txtport.Text
        Dim user As String = txtusername.Text
        Dim password As String = txtpassword.Text
        btnconnect.Enabled = False
        manager = New ManagerConnection(address, port, user, password)
        AddHandler manager.NewState, AddressOf Me.Monitoring_NewState
        AddHandler manager.UnhandledEvent, AddressOf Me.manager_Events
        Try
            manager.Login()

            If manager.IsConnected() Then
                btndisconnect.Show()
                Console.WriteLine("Conexao foi concluida com sucesso. Usuario: " & manager.Username)
                Console.ReadLine()
                Me.Hide()
            End If

        Catch ex As Exception
            Console.WriteLine("Error connect" & vbLf & ex.Message)
            manager.Logoff()
            Console.ReadLine()
        End Try
    End Sub

    Private Sub Guna2Button2_Click(sender As Object, e As EventArgs) Handles btndisconnect.Click
        manager.Logoff()
        btndisconnect.Hide()
    End Sub


    'HERE ARE THE EVENTS. ---------------------------------------

    Private Sub manager_Events(ByVal sender As Object, ByVal e As ManagerEvent)
        Console.WriteLine("Event : " & e.[GetType]().Name)
    End Sub

    Private Sub Monitoring_NewState(ByVal sender As Object, ByVal e As NewStateEvent)
        ' HERE IS THE ERROR, I CANT GET THE CALLERID OR CALLERNAME.
        Dim state As String = e.State
        Dim callerID As String = e.CallerIdNum
        Dim callerNAME As String = e.CallerIdName
        Console.WriteLine("Phone Number: ", callerID)
        Console.Write("Name: ", callerNAME)
    End Sub


End Class
1 Like

Im declaring the variable “manager” at the top of the code as you can see.

I incorrectly guessed what TryGetValue did. I thought it was part of Asternet, when it is part of .NET.

I couldn’t find any contact point for supporting AsterNET, but you need to find one, as the current forum is unlikely to be suitable for that purpose.

The first thing I would do, though, is to capture the underlying AMI protocol. People will understand what is going wrong there. I’m not sure if there are options within Asterisk, for this, but you can do it with tcpdump an wireshark.

However, based on only a short peek at the latest version of main/manager_channels.c, I get the impression that NewState events only provide the channel identification, and the new state, not all of the other potential attributes.

I think the virtual class will return something for all the attributes, but only those that actually appear in the event will contain useful values.

I am using AsterNET in my project although with C# and not VB. However, the AsterNET library should be the same.

What version of Asterisk and AsterNET library are you using?

I just did a quick test and with Asterisk 13, I’m seeing the ConnectedLineNum and ConnectedLineName getting set appropriately when ChannelState = 5 and ChannelStateDesc = Ringing

Could you run your code in debug mode and check all the variable values that are set for the NewStateEvent parameter that gets passed in?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.