Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
I am trying to build application that can auto answer the incoming calls.please help me
C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using TAPI3Lib;

namespace my_tapi
{
    public partial class Form1 : Form
    {
        private TAPIClass topj;
        uint lines;
        int line;
        uint arg3;
        private callnotification cn;
        private ITAddress[] ia = new ITAddress[10];
        private bool h323, reject;
        int[] registertoken = new int[10];
        public Form1()
        {
            InitializeComponent();
            initializetapi3();
            h323 = false;
            reject = false;
            MessageBox.Show("موجود می باشد: " + lines, "خطوط");
        }
        public void answer()
        {
            IEnumCall ec = ia[line].EnumerateCalls();
            uint arg = 0;
            ITCallInfo ici;
            try
            {
                ec.Next(1, out ici, ref arg);
                ITBasicCallControl bc = (TAPI3Lib.ITBasicCallControl)ici;
                if (!reject)
                {
                    bc.Answer();
                }
                else
                {
                    bc.Disconnect(DISCONNECT_CODE.DC_REJECTED);
                    ici.ReleaseUserUserInfo();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("There may not be any calls to answer! \n\n" + exp.ToString(), "TAPI3");
            }
        }
        public void initializetapi3()
        {
            topj = new TAPIClass();
            topj.Initialize();
            IEnumAddress ea = topj.EnumerateAddresses();
            ITAddress ln;
            uint arg3 = 0;
            lines = 0;
            cn = new callnotification();
            //cn.addtolist = new callnotification.listshow(this.status);
            topj.ITTAPIEventNotification_Event_Event += new ITTAPIEventNotification_EventEventHandler(cn.Event);
            topj.EventFilter=(int)(TAPI_EVENT.TE_CALLINFOCHANGE|TAPI_EVENT.TE_DIGITEVENT|TAPI_EVENT.TE_CALLSTATE|TAPI_EVENT.TE_PHONEEVENT|TAPI_EVENT.TE_GENERATEEVENT|TAPI_EVENT.TE_GATHERDIGITS|TAPI_EVENT.TE_REQUEST);
            for (int i = 0; i < 10; i++)
            {
                ea.Next(1, out ln, ref arg3);
                ia[i] = ln;
                if (ln != null)
                {
                    comboBox1.Items.Add(ia[i].AddressName);
                    lines++;
                }
                else
                    break;
            }
         }
        class callnotification : TAPI3Lib.ITTAPIEventNotification
        {

            public void Event(TAPI3Lib.TAPI_EVENT te, object eobj)
            {
                if (te == TAPI3Lib.TAPI_EVENT.TE_CALLSTATE)
                {
                    TAPI3Lib.ITCallStateEvent a = (TAPI3Lib.ITCallStateEvent)eobj;
                    TAPI3Lib.ITCallInfo b = a.Call;

                    if (b.CallState == TAPI3Lib.CALL_STATE.CS_OFFERING)
                    {
                        Console.WriteLine("Incoming Call!");
                        System.Threading.Thread.Sleep(2000);
                        string callerid = b.get_CallInfoString(CALLINFO_STRING.CIS_CALLERIDNUMBER);
                        Console.WriteLine(callerid);
                        callerid = b.get_CallInfoString(CALLINFO_STRING.CIS_CALLERIDNAME);
                        Console.WriteLine(callerid);
                        //answer();
                    }

                }
            }
        }
        public void status(string str)
        {
            listBox1.Items.Add(str);
        }
        static void main()
        {
            Application.Run();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("برای برقراری ارتباط توسط یکی از ورودیها ابتدا یکی را انتخاب سپس دکمه ثبت را فشار دهید", "راهنمایی");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            line = comboBox1.SelectedIndex;
        }

        private void register_Click(object sender, EventArgs e)
        {
           try
			{
				registertoken[line]=topj.RegisterCallNotifications(ia[line],true,true,TapiConstants.TAPIMEDIATYPE_AUDIO,2);	
				MessageBox.Show("Registration token : "+registertoken[line],"Registration Succeed for line "+line);
			}
			catch(Exception ein)
			{
				MessageBox.Show("خط انتخاب شده مناسب نمی باشد");
			}
        }
    }
}
Posted
Updated 9-Mar-14 9:58am
v2
Comments
Dave Kreskowiak 9-Mar-14 15:49pm    
And ....? You haven't asked a question at all.
m-e-h-d-h-i 9-Mar-14 15:54pm    
how can make this codes that can auto answer incomig call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900