← Back to team overview

wikipbx-dev team mailing list archive

Re: wikipbx Extension Templates my notes

 

Stas Shtin wrote:
> Hello Dmytro,
> 
> All in all it looks good, although there are some things that can be
> improved.
> 
> One big issue that I've noticed is that having a one-to-one mapping for
> actions and extensions means that you can't combine existing actions.
> For instance, if you create an action for dialing out, user can't just
> use it twice in order to try another number if first attempt fails. And
> you'd have to create new actions as combinations of existing ones rather
> than let user combine them on it's own. A better approach would be to
> assign multiple actions to a single template and let user specify order
> for them.
> 

Proposing one-to-one mapping, I was thinking about simplicity of
extension configuration for customer. Opening extension page user choose
required action and specify it's parameters. Having multiple actions per
extensions will require extra step in configuration: "add new action"
and other operation like changing order, removing actions.

Anyway, lets go with multiple actions per extension.

> I've written some code for possible django models below. An action
> template can have 0 or more bound variables. Action variable has double
> purpose as it's storing both choices and prompts. So the "kind" field
> stores one of the "SELECTION_CHOICES" for selections or "FIELD_CHOICES"
> for prompts. Each extension can have 0 or more bound actions and each
> action has action data for variables in action's template. I think it's
> close enough to your original idea so you can figure out how it should work.
> 
> class ActionTemplate(models.Model):
>     name = models.CharField(100)
>     description = models.TextField(blank=True)
>     xml_template = models.TextField()
> 
> 
> class ActionVariable(models.Model):
>     TYPE_CHOICES = ((0, 'Selection'), (1, 'Prompt'))
>     SELECTION_CHOICES = ((0, 'Local endpoint'), (1, 'Gateway'), (2,
> 'Audio file')) # etc..
>     FIELD_CHOICES = ((0, 'String'), (1, 'Integer'), (2, 'IP'), (3,
> 'Host')) # etc...
> 
>     template = models.ForeignKey(ActionTemplate)
>     name = models.CharField(100, blank=True)
>     variable_type = models.IntegerField(choices=TYPE_CHOICES)
>     kind = models.IntegerField(blank=True, null=True)
>     default = models.CharField(blank=True, null=True)
> 
>     class Meta:
>         unique_together = (('template', 'name'),)
> 
> 
> class Extension(models.Model):
>     owner = models.ForeignKey(User)
>     name = models.CharField(100)
> 
> 
> class Action(models.Model):
>     template = models.ForeignKey(ActionTemplate)
>     order = models.PositiveIntegerField()
> 
>     class Meta:
>         unique_together = (('template', 'order'),)
> 
> 
> class ActionData(models.Model):
>     action = models.ForeignKey(Action)
>     variable = models.ForeignKey(ActionVariable)
>     value = models.CharField(100)
> 

This model look ok for me except I don't see Action assignment to
extension. So I assume Extension may look like:

class Extension(models.Model):
    account = models.ForeignKey(Account)
    auth_call = models.BooleanField(default=True)
    dest_num = models.CharField(255)
    desc = models.CharField(255)
    is_temporary = models.BooleanField(default=False) # ? I'm not sure
if we still need this field
    priority_position = models.IntegerField()

and Action:

class Action(models.Model):
   extension = models.ForeignKey(Extension)
   template = models.ForeignKey(ActionTemplate)
   order = models.PositiveIntegerField()

    class Meta:
        unique_together = (extension template order)

> 
> I don't think that any changes for adding new actions or action
> templates are necessary in this case. Action templates would contain a
> piece of XML dialplan with some places replaceable by variables and we
> just have to specify all available SELECTION_CHOICES and FIELD_CHOICES
> values and handle them in our code.
> 
Right.


Summarizing this discussion:

- we define any possible Action template using DB model described above.
Action template code stored in DB, and its fields configured in DB.

- we support certain numbers of internal variables like end points list,
extensions list, etc. and custom defined variables (defined by admin
adding records to ActionVariable) that can be used in templates.

- We generate HTML forms for action configuration based on
ActionVariable fields description. We don't need to generate JS code as
was originally proposed in blueprint doc.


I would also like to have possibility of limiting user access to certain
actions. So users may not see all actions from ActionTemplate. That
probably can be done with django access model, but lets take case about
it later.

Dmitry

> Also, it looks like we don't really need to use django's templates here
> and just return data based our models. This means - no custom template
> loader is needed and XML template field would use normal python string
> substitution. For example, your conference template would have:
> 
> <action application="conference" data="%(conf_name)s"/>
> 
> 
> We could discuss this in a SIP call later if necessary, but it's easier
> for me to just use email at the moment as I have to spend some time
> thinking. Plus, I'd prefer to discuss this in the mailing list for
> future references.
> 
> Stas.
> 
> 
> On 01.07.2010 19:20, Dmytro Mishchenko wrote:
>> Hello Stas,
>>
>> I'm new to Django framework, so the last days was busy studying it
>> together with more deep examining of wikipbx code, your Extension
>> templates specs and also making my own notes about the way of
>> configuring extensions.
>>
>>
>> Here is my understanding of this process:
>>
>> 1.	DB structure changes.
>>
>> New table: wikipbxweb_action
>> id             1,2....
>> html_tag       raw_xml, local_endpoint, ...
>> full_name      Conference room
>> description    You can create your own conference....
>> xml_tempate    <action application="conference" data="{{ conf_name }}"/>
>>
>> Table: wikipbxweb_extension
>> ...
>> action_id	1,2....
>>
>> New table: wikipbxweb_extension_cfg
>> id		1,2,3,...
>> extension_id	21,22,22
>> name		conf_name,speak_type,speak_text
>> val		MainConferenceRoom,William,hello world
>>
>>
>> If few words:
>> - every extension has one action associated with it.
>> (It's not an action in FS term. It may be a set of actions grouped in
>> one XML template like:
>>
>> <action application="answer"/>
>> <action application="playback" data="welcome_echo.wav"/>
>> <action application="echo"/>
>> )
>>
>> - new table wikipbxweb_action used for storing XML action templates.
>> Alternatively XML code may be stored in a file and in DB we store only
>> filename.
>>
>> - new table wikipbxweb_extension_cfg used for storing action
>> configuration for certain extension
>>
>>
>> 2. We add to "ExtensionForm" class - Actions picklist (action_id in DB).
>> OnChange of this picklist we show required "DIV" block.
>>
>> Every DIV block is a set of form fields for certain action:
>> e.g. for  "Remote endpoint" it's one input field,
>> for "Speak text" it's a picklist "voice type" and input for text.
>>
>> These sets of fields probably defined in ExtensionForm code.
>>
>> 3. We need to take care about loading values for all lists possibly used
>> in extension:
>> local_endpoints, gateways, conferences, audio_files,
>> voice_types_for_speak, extensions, lua_scripts, python_scripts, js_scripts.
>>
>> 4. When the form is submitted we receive all fields and store them in
>> wikipbxweb_extension_cfg. You can see example values in DB description
>> above.
>>
>> 5. When we receive request from Freeswitch we look for an Action
>> configured for found extension, load its template and fill it with
>> variables stored in wikipbxweb_extension_cfg
>>
>> 6. If we want to add new Extension template we need:
>> - add new Action to wikipbxweb_action table
>> - add its fields to ExtensionForm code.
>> - make sure used variables available in current context.
>> - may be take care about fields initialization on editing of this kind
>> of Action.
>>
>>
>>
>> I don't like that for adding new Action we'll need to adjust the python
>>  code but it looks like the most simple way of doing it now.
>>
>> I was thinking about another approach where for adding new action user
>> provides one FS XML template and HTML template. But it seems it's not
>> the right way for Django which generates HTML based on model or form
>> description.
>>
>> I would like to hear your comments, also it'll be great to talk about
>> this stuff on the phone. If it's possible lets schedule skype call.
>>
>> Regards,
>> Dmitry
>>   
> 
> 
> 



Follow ups