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

Add contact entry to phonebook [Feature] - call_action mockup attached #50

Open
bufemc opened this issue Jun 6, 2020 · 3 comments
Open

Comments

@bufemc
Copy link
Contributor

bufemc commented Jun 6, 2020

It would be nice if you could add new phone numbers by command line. Reason: I get a lot of cold calls and it drives me nuts always to have to re-login to the Fritzbox and go to the place of the correct phonebook, then to add it. How it could work I have found here:
https://forum.fhem.de/index.php?topic=64152.0

get FritzBox tr064Command X_AVM-DE_OnTel:1 x_contact SetPhonebookEntryUID NewPhonebookID 1 NewPhonebookEntryData '<Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><contact><category>0</category><person><realName>Sperr-KONTAKT</realName></person><telephony nid="1"><number type="home" prio="1" id="0">030123456789</number></telephony></contact>'

another solution (German) here: https://administrator.de/wissen/powershell-fritzbox-tr-064-netzwerk-konfigurieren-auslesen-303474.html - check method "Add-FBPhoneBookEntry".

I currently have two phonebooks: the first for normal users, and the other is called "ColdCalls". The latter one is configured to block all contained numbers. Of course it have to be ensured you add the number to the right list ;-)

The idea would be to add it by command line, something like:

fritzphonebook -i ip -p pass -add "ColdCalls | 0700123456 | CompanyXY"

or maybe add it by the phonebook id, in my case normal numbers is 0, ColdCalls is 1:

fritzphonebook -i ip -p pass -add -pbid 1 -phone 0700123456 -name CompanyXY

I would also understand if you want to keep the phonebook read-only. So I already forked this nice repository in case I have to solve it on my own ;-)

@bufemc bufemc changed the title Add a phone number to specific phonebook [Feature / Enhancement] Add an entry to specific phonebook [Feature / Enhancement] Jun 6, 2020
@bufemc
Copy link
Contributor Author

bufemc commented Jun 15, 2020

I did a quick mockup, it works! Of course it should not be with fixed values and even the envelope hardcoded, just serve as a template. Is it worth a PR?

        fconn = FritzConnection(address=FRITZ_IP, password=FRITZ_PASS)

        arg = {'NewPhonebookID': 2, # phonebook id, JUST IN MY CASE 2 for auto blocked cold calls
               'NewPhonebookEntryID': '', # DO NOT SET TO 0, WILL OVERWRITE FIRST ENTRY!
               'NewPhonebookEntryData': '<Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><contact><category>0</category><person><realName>AutoBlockTest</realName></person><telephony nid="1"><number type="home" prio="1" id="0">009912345</number></telephony></contact></Envelope>'}

        result = fconn.call_action('X_AVM-DE_OnTel:1', 'SetPhonebookEntry', arguments=arg)

Update: Important is to set an empty string for NewPhonebookEntryID, first had it set to 0, so it always overwrote my first entry in the phonebook ;-)

@bufemc bufemc changed the title Add an entry to specific phonebook [Feature / Enhancement] Add contact entry to phonebook [Feature] - call_action mockup attached Jun 15, 2020
@cryzed
Copy link

cryzed commented Jan 6, 2021

I would also understand if you want to keep the phonebook read-only.

Why would that be desired? Is there some specific reason? I would also like to see an API for creating new entries.

@cryzed
Copy link

cryzed commented Jan 7, 2021

Here's some nicer code to create the needed entry data XML:

import xml.etree.ElementTree as ET


def get_phonebook_entry_data(name: str, number: str) -> str:
    envelope = ET.Element("Envelope", {"xmlns:s": "http://www.w3.org/2003/05/soap-envelope"})
    contact = ET.SubElement(envelope, "contact")
    category = ET.SubElement(contact, "category")
    category.text = "0"
    person = ET.SubElement(contact, "person")
    real_name = ET.SubElement(person, "realName")
    real_name.text = name
    telephony = ET.SubElement(contact, "telephony")
    number_ = ET.SubElement(telephony, "number")
    number_.text = number
    return ET.tostring(envelope, encoding="unicode")

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