Adding max_contacts to AddUser API

freepbx-15
freepbx
development
Tags: #<Tag:0x00007f4f4115c290> #<Tag:0x00007f4f4115c100> #<Tag:0x00007f4f4115bea8>

(Sholinaty) #1

I’m working on a feature improvement, but have hit a bit of confusion, hoping someone can share some wisdom.

Goal: to extend the GraphQL “AddExtension” and “UpdateExtension” API’s to accept a max_contacts variable (if the technology is set to PJSIP) to allow for setting this troublesome little setting at user creation.

JIRA: https://issues.freepbx.org/browse/FREEPBX-22723

The Rabbit Hole:
it looks like max_contacts is stored in the sip SQL table as {id,keyword,data} of {extension, max_contacts, # }

Looking through the FreePBX Source, in the Core Module for release 15

  1. the GraphQL API for AddExtension passes the data to
    $this->freepbx->Core->processQuickCreate($input['tech'],$input['extension'],$input);

  2. in Core.class.php,
    ProcessQuickCreate calls this->addDevice
    addDevice only seems to touch the DEVICE table, which does not store max_contacts.

  3. if you look at the EmergencyAddDevice, it directly interacts with the sip SQL table

if($tech == 'sip' || $tech == 'pjsip') {
			$sql = 'INSERT INTO sip (id, keyword, data, flags) values (?,?,?,?)';
			$sth = $this->database->prepare($sql);
			$settings = is_array($settings)?$settings:array();
			foreach($settings as $key => $setting) {
				if($key == 'calleridname') {
					continue; // addtional param we dont want this in sip table But need it in astDB
				}
				$sth->execute(array($id,$key,$setting['value'],$setting['flag']));
			}

Boiling down my post into questions:

  1. how does a Normal extension/device get into the SQL sip table if the Add function doesn’t seem to invoke the sip commands?
    I’ve run the code… it ends up there… but its not Called by the API code.

  2. any suggestions / what would be the best way to inject in a field such as max_contacts?
    from what I can see, it lives in the sip table, and nowhere else.


(TheJames) #2

The first rule of Fight Club FreePBX Development is never access another module’s data directly. This means for any given purpose the module should manage its own data.

What you are trying to do is expose a setting. This setting is the same as any other and is just a matter of adding some lines to the resolvers in.

Nothing fancy needed. Unfortunately it is not written in a way to expose different settings for different drivers so it will show for pjsip and chan_sip. It will simply be ignored on non pjsip extensions.


(TheJames) #3

Side note, settings by device type…


(Sholinaty) #4

thank you @jfinstrom
that is part of where I get stuck.
in that same module, the ProcessEmergencyQuickCreate seems to do exactly what I was referring to (whether that’s RIGHT or not… is debatable).

I really appreciate the code snippets. It will take me a bit of time to decode/investigate them.

in theory, once I get the getDefaultDeviceSettings, I should be able to tinker/modify them as needed?


(Sholinaty) #5

max_contacts IS a field returned by the PJSIP getDefaultDeviceSettings
Ive got an idea… coding up a test now.


(Sholinaty) #6

hahahahaha its alive! its aliiiiiiive!

need code cleanup, but i AM successfully able to set max_contacts via the graphql API now.


(Sholinaty) #7

hit a snag.
{
“errors”: [
{
“message”: “Field “max_contacts” is not defined by type addExtensionInput.”,
“status”: false
}
]
}

Have to find out where the Type is defined. having a hard time finding it.


(TheJames) #8

It is in the first link I posted


(Sholinaty) #9

pull request is submitted: https://git.freepbx.org/projects/FREEPBX/repos/core/pull-requests/399/overview


(Jared Busch) #10

Great! I will almost certainly make use of this as I always want max contacts to be >1
I have an improvement to User manager that I need to fix so I can get my pull request approved.


(Sholinaty) #11

awesome!
i think my next goal here is being able to set the voicemail sub-options (envelope, email, sayCID,delete) at Creation (addExtension, updateExtension) rather than needing a 2nd graphql call… but that wont be today.


(system) closed #12

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