Author: |
KMEE Informática LTDA |
License: |
AGPL-3 |
Branch: |
feature/totalvoice_odoo |
Repository: |
kmee/web |
Dependencies: |
base,
and
webhook |
Languages: |
PO File (213, 18.7%),
Python (593, 52.1%),
XML (283, 24.9%),
and
reStructuredText (49, 4.3%) |
<h1 class="title">TotalVoice Odoo</h1>
<p>Module created to integrate the TotalVoice API with Odoo.</p>
<p>This module manage to send and receive SMS messages, invoking
methods to process the webhook events.</p>
<a name="configuration"></a>
<h2>Configuration</h2>
<p>First, you will need to <a class="reference external" href="https://www.totalvoice.com.br/signup.php">create a TotalVoice Account</a></p>
<p>After creating you account, the next step is to configure your 'Webhook de
Resposta de SMS' in the 'Minha Conta / Configurações da API' menu.</p>
<p>In this page, you should set the 'Webhook de Resposta de SMS' field with
your <strong>webhook url</strong>. For example:</p>
<pre>
<code lang="xml">http://prod.yourcompany.odoo.com.br/webhook/totalvoice</code>
</pre>
<p>Notice the <strong>webhook/totalvoice</strong> after your Odoo URL. That is important.</p>
<p>The next step is to retrieve your <strong>Access-Token</strong>. It can be found in the
<cite>website main panel <https://api.totalvoice.com.br/painel> _</cite></p>
<p>Now paste your Access-Token in the totalvoice_odoo module configuration
page and then save.</p>
<pre>
<code lang="xml">API-KEY: your access-token
API-URL: api.totalvoice.com.br</code>
</pre>
<p>Now, in the Odoo Configuration page, go in
'Technical/Automation/Webhook' and search for the TotalVoice
consumer_name. Insert your <strong>webhook-url</strong> in the field <strong>IP or Network
Address</strong>, overriding the existing one.</p>
<pre>
<code lang="xml">http://prod.yourcompany.odoo.com.br/webhook/totalvoice</code>
</pre>
<a name="webhook-usage"></a>
<h2>Webhook Usage</h2>
<p>In order to use the Webhook event handler, you must create a new class in
your module, inheriting 'totalvoice.base'.</p>
<p>In this class, you should be able to add new <strong>subjects</strong> to the subject
field declared in the totalvoice.base. The subject name will be used to
form the method name which will be called.</p>
<p>Example of methods the webhook will call:</p>
<pre>
<code lang="xml">def confirm_operation_yes(self, *args)
def confirm_operation_no(self, *args)
def assign_task_yes(self, *args)
def assign_task_no(self, *args)</code>
</pre>
<dl class="docutils">
<dt>Where <strong>confirm_operation</strong> and <strong>assign_task</strong> are names of new subjects,</dt>
<dd><strong>yes</strong> and <strong>no</strong> are possible answers to the sent SMS and <strong>*args</strong> is
the text after the first word in the SMS answer.</dd>
</dl>
<p>Below is a clearer example of how to override the totalvoice.base class</p>
<pre>
<code lang="python">SUBJECT_SELECTION = [
('assign_task', 'Assign a Task'),
('cancel_assign', "Cancel an Assigned Task"),
]
class TotalVoiceBase(models.Model):
_inherit = 'totalvoice.base'
healthprofessional_id = fields.Many2one(
string="Health Professional",
comodel_name='pontomedical.healthprofessional',
ondelete='cascade',
)
subject = fields.Selection(
selection_add=SUBJECT_SELECTION,
)
@api.multi
def assign_task_0(self, *args):
self.ensure_one()
self.healthprofessional_id.confirm_appointments()
@api.multi
def assign_task_1(self, *args):
self.ensure_one()
self.healthprofessional_id.confirm_appointments(appointments=None)
@api.multi
def cancel_assign_YES(self, *args):
self.ensure_one()
self.healthprofessional_id.cancel_assign(attach_reason=args)</code>
</pre>
<p>So, if the following SMS is sent to the user with the subject
<strong>cancel_assign</strong>:</p>
<pre>
<code lang="xml">Do you want to cancel the assign? Type YES if you do want, following by
your reasons.</code>
</pre>
<p>The user can answer that with, for example:</p>
<pre>
<code lang="xml">YES. Because tomorrow is my son's birthday.</code>
</pre>
<p>In this situation, the method <strong>cancel_assign_YES</strong> will be called, and
<strong>*args*</strong> will be filled with the string 'Because tomorrow is my son's
birthday.'.</p>
<a name="bug-tracker"></a>
<h2>Bug Tracker</h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/KMEE/web/issues">GitHub Issues</a>. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.</p>
<a name="contributors"></a>
<h3>Contributors</h3>
<ul class="simple">
<li>Hugo Uchoas Borges <<a class="reference external" href="mailto:hugo.borges@kmee.com.br">hugo.borges@kmee.com.br</a>></li>
</ul>