Skip to content

Commit

Permalink
Added changes to configure combined webchat
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-palii committed Sep 27, 2023
1 parent 9886197 commit 0b50dae
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
4 changes: 4 additions & 0 deletions temba/channels/types/webchat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def form_valid(self, form):
"store_history": False,
"width": 400,
"height": 550,
"allow_attachments": True,
"allow_multi_language": True,
"allow_fab_text": False,
"fab_text": "",
}
for lang in org.flow_languages:
lang_alpha = pycountry.languages.get(alpha_3=lang)
Expand Down
41 changes: 41 additions & 0 deletions temba/channels/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,10 @@ def __init__(self, *args, **kwargs):
self.fields["inputtext_placeholder_default"].initial = config.get("inputtext_placeholder_default", "")

self.fields["store_history"].initial = config.get("store_history", False)
self.fields["allow_attachments"].initial = config.get("allow_attachments", False)
self.fields["allow_multi_language"].initial = config.get("allow_multi_language", False)
self.fields["allow_fab_text"].initial = config.get("allow_fab_text", False)
self.fields["fab_text"].initial = config.get("fab_text", "")

response_fonts = requests.get(
f"https://www.googleapis.com/webfonts/v1/webfonts?key={settings.GOOGLE_FONT_API_KEY}"
Expand Down Expand Up @@ -1112,6 +1116,43 @@ def add_extra_fields(self):
default=False,
)

self.add_config_field(
"allow_attachments",
forms.BooleanField(
label=_("Allow Attachments"),
help_text=_("Check this box whether the attachment icon is available for this WebChat"),
required=False,
),
default=False,
)

self.add_config_field(
"allow_multi_language",
forms.BooleanField(
label=_("Allow Language Select"),
help_text=_("Check this box whether the language selection is available for this WebChat"),
required=False,
),
default=False,
)

self.add_config_field(
"allow_fab_text",
forms.BooleanField(
label=_("Use a text button"),
help_text=_(
"Whether you want to use a text button instead of icon "
"(you can specify text you want once you checking this box)"
),
required=False,
),
default=False,
)

self.add_config_field(
"fab_text", forms.CharField(label=_("Text for the button"), max_length=64, required=False), default=False
)

unlisted_fields = ["name", "alert_email"]

for field in list(self.fields):
Expand Down
32 changes: 31 additions & 1 deletion templates/channels/channel_update.haml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@
{% render_field "logo_style" %}
{% render_field "title" %}
{% render_field "store_history" %}
{% render_field "allow_attachments" %}
{% render_field "allow_multi_language" %}
.control-group.field_allow_fab_text
.controls
<temba-checkbox
id="id_fab_text_toggle"
name="{{form.allow_fab_text.name}}"
label="{{form.allow_fab_text.label}}"
help_text="{{form.allow_fab_text.help_text}}"
errors="{{form.allow_fab_text.errors}}"
{% if form.allow_fab_text.value %}checked{% endif %}>
</temba-checkbox>
<div style="padding-left: 33px">
<temba-textinput
id="id_fab_text"
type="text"
name="{{form.fab_text.name}}"
value="{{form.fab_text.value}}"
class="{% if not form.allow_fab_text.value %}hide{% endif %}"
maxlength="64">
</temba-textinput>
</div>
</div>
</div>

Expand Down Expand Up @@ -418,7 +440,7 @@
el.slideDown();
});

buildGoogleFontLink($("temba-select[name='google_font']").find("temba-option[selected]")[0].attributes.value.nodeValue);
buildGoogleFontLink($("temba-select[name='google_font']").find("temba-option[selected]")[0]?.attributes?.value?.nodeValue);

{% for item in customable_fields %}
$("{{ item }}").blur(function() {
Expand Down Expand Up @@ -512,6 +534,14 @@
$("textarea").removeAttr("required");

buildWebChat(welcomeMsgValues, inputTextPlaceholderValues, "{{ form.google_font.value }}", "{{ form.logo_style.value }}", "{{ form.side_of_screen.value }}", "{{ form.welcome_msg_quick_replies.value|safeseq|join:',' }}");

$("#id_fab_text_toggle").change(function() {
if ($(this).val()) {
$("#id_fab_text").removeClass("hide");
} else {
$("#id_fab_text").addClass("hide");
}
});
});
{% endif %}
})(jQuery);
Expand Down
3 changes: 3 additions & 0 deletions templates/channels/types/webchat/config.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
welcomeMessageQuickReplies: {{ channel.config.welcome_msg_quick_replies|adapt_for_widget_list }},
inputTextPlaceholder: '{{ channel.config.inputtext_placeholder_default|adapt_for_widget }}',
inputTextPlaceholderI18n: {{ input_placeholder_i18n }},
allowAttachments: {{ channel.config.allow_attachments|adapt_for_widget_bool }},
enableLanguageSelector: {{ channel.config.allow_multi_language|adapt_for_widget_bool }},
fabText: {% if channel.config.allow_fab_text %}'{{channel.config.fab_text|adapt_for_widget}}'{% else %}undefined{% endif %},
theme: {
widgetBackgroundColor: '{{ "#"|add:channel.config.widget_bg_color }}',
chatHeaderBackgroundColor: '{{ "#"|add:channel.config.chat_header_bg_color }}',
Expand Down

0 comments on commit 0b50dae

Please sign in to comment.