Skip to content

Commit

Permalink
Add message_template that allows to configure a template that define …
Browse files Browse the repository at this point in the history
…how the message is sent with agent name
  • Loading branch information
dudanogueira committed Apr 3, 2023
1 parent 9b9354a commit cb3f08f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions rocket_connect/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ def get_agent_name(self, message):

return self.change_agent_name(agent_name)

def render_message_agent_template(self, message, agent_name):
context = {"message": message, "agent_name": agent_name}
context = Context(context)
default_message_template = "*[{{agent_name}}]*\n{{message}}"
message_template = self.config.get("message_template", default_message_template)
template = Template(message_template)
message = template.render(context)
return message

def get_close_message(self, department=None):
"""
get the close message configured for the connector
Expand Down Expand Up @@ -972,6 +981,12 @@ def save(self):
help_text="Do not create/get rooms for this tokens", required=False
)
timezone = forms.CharField(help_text="Timezone for this connector", required=False)
message_template = forms.CharField(
widget=forms.Textarea(attrs={"rows": 4, "cols": 15}),
help_text="Template to render message, (default): *[{{agent_name}}]*\n{{message}}",
required=False,
initial="*[{{agent_name}}]*\n{{message}}",
)
force_close_message = forms.CharField(
widget=forms.Textarea(attrs={"rows": 4, "cols": 15}),
help_text="Force this message on close",
Expand Down
3 changes: 2 additions & 1 deletion rocket_connect/plugins/wppconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,8 @@ def outgo_text_message(self, message, agent_name=None):
content = self.joypixel_to_unicode(content)
# message may not have an agent
if agent_name:
content = "*[" + agent_name + "]*\n" + content
content = self.render_message_agent_template(content, agent_name)
# content = "*[" + agent_name + "]*\n" + content

payload = {
"phone": self.get_visitor_id(),
Expand Down

0 comments on commit cb3f08f

Please sign in to comment.