Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays the number you are calling, e.g. where the code is running 793456, if I am calling from 07770 456 789, 793456 pops up #1

Open
Bignose3 opened this issue Jan 25, 2025 · 4 comments

Comments

@Bignose3
Copy link

Hi,

Thank you very much for this code, as you say no one else has anytihng out there, works'ish straight out of the box once modules installed

HOWEVER
Windows 10
I might be able to work out but could not see immediately,

Tapi is on a local unit PBX with all set up fine, use to use a VB OCX but depreciated but that picked up the caller ID fine on the same setting/line/ext.

I have extension 10 to pick up all incoming call whether external or internal intercom.

So if I internal call from my ext no. 27 to 10, 10 is show in the popup.
If I call from an outside line, e.g. my mobile the master PBX number is show. not the calling number.

Any advise, to be honest I cannot see where the number that pop's up is sourced.
Been a while since I was using python, do love it but a bit of a learning curve to get back into it hence perhaps a stupid question.

@Bignose3
Copy link
Author

Bignose3 commented Jan 25, 2025

I'm the OP, sorted, seems I was missing the obvious

output was just getting the last of the 3 values that are returned, I need the 2nd, the 27 so can easily fix
Thanks again, I spend days trying to get Caller ID into my access database using VBA, just no examples, some VBnet, powerbasic. lots of fairly tricky code that just does not seem to work. Farily easy & hopefully effective to export/link this info in MS Access.

amazing the basics of win32com.client & pythoncom seem to manage easily & minimal code. I may have towork out a way to go through the source of TAPI, on the PC I want to use eventually has a few modems. My test PC only has the one, NEC Tapi.

output = obj.CallInfoString(code)
print (output)    #  "NEC Tapi", caller ID ="27" , number being called ="10"  
if bool(output):
   if print_console:
      print(f"{str}: {output}")
   else:
      update_text(f"{str}:\n{output}")

except:
pass

@lwcorp
Copy link
Owner

lwcorp commented Jan 25, 2025

Thanks for trying it and I'll try to assist! It's a bit hard to follow though - do you mean your actual output is "NEC Tapi", caller ID ="27" , number being called ="10"?

Either way, please:

  1. Quote exactly which output you actually get when calling from outside
  2. Quote exactly which output you should get when calling from outside

Then:

  1. Quote exactly which output you actually get when calling from inside
  2. Quote exactly which output you should get when calling from inside

@Bignose3
Copy link
Author

I did reply to your direct email but thought would post here also in case of use to others, made a little clearer below I hope.

Hi,

I am just interested in Caller ID for incoming calls.

It is working correctly now, not sure if by design or luck until I really understand the process.

Fairly sure it is because of duplicate
print_check_error(f"CIS_CALLERIDNUMBER", call, constants.CIS_CALLERIDNUMBER)
# print_check_error(f"CIS_CALLEDIDNUMBER", call, constants.CIS_CALLEDIDNUMBER)
I have # it out & working OK.

I am guessing may work differently on your system as no doubt would have had the same problem, perhaps because mine is on a pbx,
It seems to pick up the true, correct, incoming number but then loops & gets the next one which is the number I am Dialing & it is this wrong one that gets passed so # out as above so you just get the 2 results, the Tapi Name "NEcTapi" & the correct callerID, so all good now.

You have already done enough & I am sure I will work it out now I have a great example to go on but if you have any advise on how I might go about listing & the selecting the TAPI source. On this windows 10 test system I have just one TAPI source, the NEC pbx. On the Windows 10 PC I will eventually implement has 2 or more TAPI devices.
I am guess yours just picks the first if finds.

My old VBA ocx, I could list them all & then choose a device number but this was described in the 3rd party manual so easy to code.

Huge thanks again, I had rather lost the will with trying to get VBA to work & could not have faced trying again via Python still not knowing if it would have worked in the end. Even though you & the modules have done all the work still seems so much easier than MS Tapi32 VBNet etc.
Will be easy for me to pass this number to MSAccess one way or the other & actually much prefer having control myself with a python program running in the background.

Work in progress & guess unlikely someone viewing here is after connecting to MSAccess but here is what I have work in at the moment.

import win32com.client
import pythoncom, time
import pyodbc as pyo

cnn_string = (
r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
r"DBQ=C:\Users\Joe Bloggs\Documents\TAPI_Init.accdb"
)

def print_check_error(str, obj, code):
try:
output = obj.CallInfoString(code)
# "NEC Tapi", caller ID ="27" , BEFORE the #ing out above, ALSO ..number being called ="10"
if bool(output):
if print_console:
print("1st")
print(f"{str}: {output}")
else:
update_text(f"{str}:\n{output}")
TelNo = (output)
TelTime = (time.strftime("%d-%b-%Y %H:%M"))

          cursor.execute(''' INSERT INTO CallerIDTable (TelNo, TelTime) VALUES(?,?) ''', (TelNo, TelTime))
          print ("executed")
          cursor.commit()
          print("committed")
except:
    pass

Access table name & fields must be identical, also other stuff is case sensitive, just double check.
My MSAccess is still 32bit so HAVE to use 32bit Python, I have both installed & tricky to make sure it uses this version each time but Idle can open either one. Also installing Win32com & running python com initially error'd on install, lots of restarts & eventually worked, not sure what I did that fixed it.
Sure my comments are obvious to those reading hear as far more skilled than me but thought would comment anyway

@lwcorp
Copy link
Owner

lwcorp commented Jan 30, 2025

This ticket is about weird numbers, so please consider writing the MSAccess code in a standalone ticket as a feature request.

Fairly sure it is because of duplicate
print_check_error(f"CIS_CALLERIDNUMBER", call, constants.CIS_CALLERIDNUMBER)

print_check_error(f"CIS_CALLEDIDNUMBER", call, constants.CIS_CALLEDIDNUMBER)

It's not a duplicate:

  1. CIS_CALLE​R​IDNUMBER is "the number of the caller".
  2. CIS_CALLE​D​IDNUMBER is "the number of the connected location". There's no further documentation online but AI Chatbots assume it's your number (the person or destination being called).

I guess by default it's undetected thus empty, but your PBX does know how to fill it which looks weird to you.
So I've just updated the code to write full descriptions to make it clearer.
Commenting out is exactly what you should do if you don't want to display something, but keep in mind every output is technically legit, it's your call what to display or not.

I've also updated the code to let you choose which modem to use. I originally figured if someone had multiple modems, they'd want to know when any of them called.

Kindly test the updated Caller ID code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants