mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	# Pull Request Template
## Description
This PR allows users to dynamically pass custom welcome and availability
messages, along with UI feature toggles, via `window.chatwootSettings`.
If any of the following settings are provided, the widget will use them;
otherwise, it falls back to default behavior.
**New options:**
```
window.chatwootSettings = {
  welcomeTitle: 'Need help?',                        // Custom widget title
  welcomeDescription: 'We’re here to support you.',        // Subtitle in the header
  availableMessage: 'We’re online and ready to chat!', // Shown when team is online
  unavailableMessage: 'We’re currently offline.',      // Shown when team is unavailable
  enableFileUpload: true,          // Enable file attachments
  enableEmojiPicker: true,         // Enable emoji picker in chat input
  enableEndConversation: true     // Allow users to end the conversation
}
```
Fixes
https://linear.app/chatwoot/issue/CW-4589/add-options-to-windowchatwootsettings
## Type of change
- [x] New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
### Loom video
https://www.loom.com/share/413fc4aa59384366b071450bd19d1bf8?sid=ff30fb4c-267c-4beb-80ab-d6f583aa960d
## Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
---------
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
		
	
		
			
				
	
	
		
			190 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Vue
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			190 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			Vue
		
	
	
		
			Executable File
		
	
	
	
	
<script>
 | 
						|
import { mapGetters } from 'vuex';
 | 
						|
 | 
						|
import ChatAttachmentButton from 'widget/components/ChatAttachment.vue';
 | 
						|
import ChatSendButton from 'widget/components/ChatSendButton.vue';
 | 
						|
import configMixin from '../mixins/configMixin';
 | 
						|
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
 | 
						|
import ResizableTextArea from 'shared/components/ResizableTextArea.vue';
 | 
						|
 | 
						|
import EmojiInput from 'shared/components/emoji/EmojiInput.vue';
 | 
						|
 | 
						|
export default {
 | 
						|
  name: 'ChatInputWrap',
 | 
						|
  components: {
 | 
						|
    ChatAttachmentButton,
 | 
						|
    ChatSendButton,
 | 
						|
    EmojiInput,
 | 
						|
    FluentIcon,
 | 
						|
    ResizableTextArea,
 | 
						|
  },
 | 
						|
  mixins: [configMixin],
 | 
						|
  props: {
 | 
						|
    onSendMessage: {
 | 
						|
      type: Function,
 | 
						|
      default: () => {},
 | 
						|
    },
 | 
						|
    onSendAttachment: {
 | 
						|
      type: Function,
 | 
						|
      default: () => {},
 | 
						|
    },
 | 
						|
  },
 | 
						|
  data() {
 | 
						|
    return {
 | 
						|
      userInput: '',
 | 
						|
      showEmojiPicker: false,
 | 
						|
      isFocused: false,
 | 
						|
    };
 | 
						|
  },
 | 
						|
 | 
						|
  computed: {
 | 
						|
    ...mapGetters({
 | 
						|
      widgetColor: 'appConfig/getWidgetColor',
 | 
						|
      isWidgetOpen: 'appConfig/getIsWidgetOpen',
 | 
						|
      shouldShowFilePicker: 'appConfig/getShouldShowFilePicker',
 | 
						|
      shouldShowEmojiPicker: 'appConfig/getShouldShowEmojiPicker',
 | 
						|
    }),
 | 
						|
    showAttachment() {
 | 
						|
      return (
 | 
						|
        this.shouldShowFilePicker &&
 | 
						|
        this.hasAttachmentsEnabled &&
 | 
						|
        this.userInput.length === 0
 | 
						|
      );
 | 
						|
    },
 | 
						|
    showSendButton() {
 | 
						|
      return this.userInput.length > 0;
 | 
						|
    },
 | 
						|
  },
 | 
						|
  watch: {
 | 
						|
    isWidgetOpen(isWidgetOpen) {
 | 
						|
      if (isWidgetOpen) {
 | 
						|
        this.focusInput();
 | 
						|
      }
 | 
						|
    },
 | 
						|
  },
 | 
						|
  unmounted() {
 | 
						|
    document.removeEventListener('keypress', this.handleEnterKeyPress);
 | 
						|
  },
 | 
						|
  mounted() {
 | 
						|
    document.addEventListener('keypress', this.handleEnterKeyPress);
 | 
						|
    if (this.isWidgetOpen) {
 | 
						|
      this.focusInput();
 | 
						|
    }
 | 
						|
  },
 | 
						|
 | 
						|
  methods: {
 | 
						|
    onBlur() {
 | 
						|
      this.isFocused = false;
 | 
						|
    },
 | 
						|
    onFocus() {
 | 
						|
      this.isFocused = true;
 | 
						|
    },
 | 
						|
    handleButtonClick() {
 | 
						|
      if (this.userInput && this.userInput.trim()) {
 | 
						|
        this.onSendMessage(this.userInput);
 | 
						|
      }
 | 
						|
      this.userInput = '';
 | 
						|
      this.focusInput();
 | 
						|
    },
 | 
						|
    handleEnterKeyPress(e) {
 | 
						|
      if (e.keyCode === 13 && !e.shiftKey) {
 | 
						|
        e.preventDefault();
 | 
						|
        this.handleButtonClick();
 | 
						|
      }
 | 
						|
    },
 | 
						|
    toggleEmojiPicker() {
 | 
						|
      this.showEmojiPicker = !this.showEmojiPicker;
 | 
						|
    },
 | 
						|
    hideEmojiPicker(e) {
 | 
						|
      if (this.showEmojiPicker) {
 | 
						|
        e.stopPropagation();
 | 
						|
        this.toggleEmojiPicker();
 | 
						|
      }
 | 
						|
    },
 | 
						|
    emojiOnClick(emoji) {
 | 
						|
      this.userInput = `${this.userInput}${emoji} `;
 | 
						|
    },
 | 
						|
    onTypingOff() {
 | 
						|
      this.toggleTyping('off');
 | 
						|
    },
 | 
						|
    onTypingOn() {
 | 
						|
      this.toggleTyping('on');
 | 
						|
    },
 | 
						|
    toggleTyping(typingStatus) {
 | 
						|
      this.$store.dispatch('conversation/toggleUserTyping', { typingStatus });
 | 
						|
    },
 | 
						|
    focusInput() {
 | 
						|
      this.$refs.chatInput.focus();
 | 
						|
    },
 | 
						|
  },
 | 
						|
};
 | 
						|
</script>
 | 
						|
 | 
						|
<template>
 | 
						|
  <div
 | 
						|
    class="items-center flex ltr:pl-3 rtl:pr-3 ltr:pr-2 rtl:pl-2 rounded-[7px] transition-all duration-200 bg-n-background !shadow-[0_0_0_1px,0_0_2px_3px]"
 | 
						|
    :class="{
 | 
						|
      '!shadow-n-brand dark:!shadow-n-brand': isFocused,
 | 
						|
      '!shadow-n-strong dark:!shadow-n-strong': !isFocused,
 | 
						|
    }"
 | 
						|
    @keydown.esc="hideEmojiPicker"
 | 
						|
  >
 | 
						|
    <ResizableTextArea
 | 
						|
      id="chat-input"
 | 
						|
      ref="chatInput"
 | 
						|
      v-model="userInput"
 | 
						|
      :rows="1"
 | 
						|
      :aria-label="$t('CHAT_PLACEHOLDER')"
 | 
						|
      :placeholder="$t('CHAT_PLACEHOLDER')"
 | 
						|
      class="user-message-input reset-base"
 | 
						|
      @typing-off="onTypingOff"
 | 
						|
      @typing-on="onTypingOn"
 | 
						|
      @focus="onFocus"
 | 
						|
      @blur="onBlur"
 | 
						|
    />
 | 
						|
    <div class="flex items-center ltr:pl-2 rtl:pr-2">
 | 
						|
      <ChatAttachmentButton
 | 
						|
        v-if="showAttachment"
 | 
						|
        class="text-n-slate-12"
 | 
						|
        :on-attach="onSendAttachment"
 | 
						|
      />
 | 
						|
      <button
 | 
						|
        v-if="shouldShowEmojiPicker && hasEmojiPickerEnabled"
 | 
						|
        class="flex items-center justify-center min-h-8 min-w-8"
 | 
						|
        :aria-label="$t('EMOJI.ARIA_LABEL')"
 | 
						|
        @click="toggleEmojiPicker"
 | 
						|
      >
 | 
						|
        <FluentIcon
 | 
						|
          icon="emoji"
 | 
						|
          class="transition-all duration-150"
 | 
						|
          :class="{
 | 
						|
            'text-n-slate-12': !showEmojiPicker,
 | 
						|
            'text-n-brand': showEmojiPicker,
 | 
						|
          }"
 | 
						|
        />
 | 
						|
      </button>
 | 
						|
      <EmojiInput
 | 
						|
        v-if="shouldShowEmojiPicker && showEmojiPicker"
 | 
						|
        v-on-clickaway="hideEmojiPicker"
 | 
						|
        :on-click="emojiOnClick"
 | 
						|
        @keydown.esc="hideEmojiPicker"
 | 
						|
      />
 | 
						|
      <ChatSendButton
 | 
						|
        v-if="showSendButton"
 | 
						|
        :color="widgetColor"
 | 
						|
        @click="handleButtonClick"
 | 
						|
      />
 | 
						|
    </div>
 | 
						|
  </div>
 | 
						|
</template>
 | 
						|
 | 
						|
<style scoped lang="scss">
 | 
						|
.emoji-dialog {
 | 
						|
  @apply max-w-full ltr:right-5 rtl:right-[unset] rtl:left-5 -top-[302px] before:ltr:right-2.5 before:rtl:right-[unset] before:rtl:left-2.5;
 | 
						|
}
 | 
						|
 | 
						|
.user-message-input {
 | 
						|
  @apply border-none outline-none w-full placeholder:text-n-slate-10 resize-none h-8 min-h-8 max-h-60 py-1 px-0 my-2 bg-n-background text-n-slate-12 transition-all duration-200;
 | 
						|
}
 | 
						|
</style>
 |