diff --git a/rocket_connect/plugins/base.py b/rocket_connect/plugins/base.py index 6a6867f..9a9a650 100644 --- a/rocket_connect/plugins/base.py +++ b/rocket_connect/plugins/base.py @@ -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 @@ -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", diff --git a/rocket_connect/plugins/wppconnect.py b/rocket_connect/plugins/wppconnect.py index 29f7df7..67bd94b 100644 --- a/rocket_connect/plugins/wppconnect.py +++ b/rocket_connect/plugins/wppconnect.py @@ -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(),