+ {{ + AppStore.connection.host + .replace(/https?:\/\//, "") + .replace(/\/$/, "") + }} +
+v{{ version }}
@@ -70,7 +70,7 @@ export default { { title: "Doc", icon: "mdi-book-open-page-variant", - url: "https://doc.evolution-api.com/help-center", + url: "https://doc.evolution-api.com", }, ], }), diff --git a/src/layouts/doc/AppBar.vue b/src/layouts/doc/AppBar.vue index feccbae..9d7aea8 100644 --- a/src/layouts/doc/AppBar.vue +++ b/src/layouts/doc/AppBar.vue @@ -52,6 +52,7 @@ export default { lang_list: [ { title: "Português", value: "pt_br" }, { title: "English", value: "en" }, + { title: "Español", value: "es" }, ], DocStore: useDocStore(), }), diff --git a/src/plugins/index.js b/src/plugins/index.js index c71748d..5f9b86c 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -5,7 +5,7 @@ */ // Plugins -import vuetify from './vuetify' +import { vuetify,i18n } from './vuetify' import pinia from '../store' import router from '../router' @@ -13,6 +13,7 @@ import HelpTooltip from '@/components/global/HelpTooltip.vue' export function registerPlugins(app) { app + .use(i18n) .use(vuetify) .use(router) .use(pinia) diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index cca6b91..f505884 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -10,11 +10,35 @@ import 'vuetify/styles' // Composables import { createVuetify } from 'vuetify' +import { createVueI18nAdapter } from 'vuetify/locale/adapters/vue-i18n' +import { createI18n, useI18n } from 'vue-i18n' + + +// import all files from src/i18n +const messages = Object.fromEntries( + Object.entries( + import.meta.glob('../i18n/*.js', { eager: true }) + ).map(([key, value]) => { + const locale = key.match(/([A-Za-z0-9-_]+)\./i)[1] + return [locale, value.default] + }) +) + +const locale = window.localStorage.getItem('locale') || 'pt' +export const i18n = createI18n({ + legacy: false, // Vuetify does not support the legacy mode of vue-i18n + locale, + fallbackLocale: 'pt', + messages, +}) + -const defaultTheme = localStorage.getItem('theme') || 'light' -// https://vuetifyjs.com/en/introduction/why-vuetify/#feature-guides -export default createVuetify({ +const defaultTheme = localStorage.getItem('theme') || 'light' +export const vuetify = createVuetify({ + locale: { + adapter: createVueI18nAdapter({ i18n, useI18n }), + }, theme: { defaultTheme, themes: { @@ -27,3 +51,10 @@ export default createVuetify({ }, }, }) + + +export default { + vuetify, + i18n +} + diff --git a/src/services/instanceSettingsController.js b/src/services/instanceSettingsController.js index ec88167..3cac46b 100644 --- a/src/services/instanceSettingsController.js +++ b/src/services/instanceSettingsController.js @@ -141,7 +141,16 @@ const setTypebot = async (instanceName, data) => { }); } - +const changeTypebotStatus = async (instanceName, data) => { + return await http + .post("/typebot/changeStatus/:instance", data, { + params: { instance: instanceName } + }) + .then((r) => r.data) + .catch((error) => { + throw error.response?.data || error.response || error + }) +} export default { options: { @@ -168,5 +177,6 @@ export default { typebot: { get: findTypebot, set: setTypebot, + changeStatus: changeTypebotStatus, } } \ No newline at end of file diff --git a/src/store/app.js b/src/store/app.js index 8af7dba..ca1fb75 100644 --- a/src/store/app.js +++ b/src/store/app.js @@ -1,7 +1,7 @@ // Utilities import axios from 'axios' import { defineStore } from 'pinia' - +import semver from 'semver' export const useAppStore = defineStore('app', { getters: { @@ -14,10 +14,15 @@ export const useAppStore = defineStore('app', { return state.getInstance(instance).instance.apiKey || state.instancesKeys[instance] }, + version: (state) => state.connection.version, + versionSatisfies: (state) => (version) => { + return semver.satisfies(state.connection.version, version) + }, }, state: () => ({ connecting: false, connection: { + valid: false, host: null, globalApiKey: null, @@ -33,20 +38,32 @@ export const useAppStore = defineStore('app', { async setConnection({ host, globalApiKey }) { try { this.connecting = true - const response = await axios({ + const apiResponse = await axios({ method: 'GET', baseURL: host, headers: { 'Content-Type': 'application/json', 'apikey': globalApiKey }, - url: '/instance/fetchInstances' + url: '/' }) - if (!response.data || !Array.isArray(response.data)) throw new Error('Essa conexão não é uma instância da evolution-api') + if (!apiResponse.data || !apiResponse.data.message || !apiResponse.data.message.includes('Evolution API')) { + throw new Error('Essa conexão não é uma instância da evolution-api') + } + const { version } = apiResponse.data + const response = await axios({ + method: 'GET', + baseURL: host, + headers: { + 'Content-Type': 'application/json', + 'apikey': globalApiKey + }, + url: '/instance/fetchInstances' + }) - this.saveConnection({ host, globalApiKey }) + this.saveConnection({ host, globalApiKey, version }) this.instancesList = response.data } catch (e) { this.connection.valid = false @@ -59,18 +76,7 @@ export const useAppStore = defineStore('app', { async loadInstance(instanceName) { try { console.log('loadInstance', instanceName) - // const { host, globalApiKey } = this.connection; return this.reconnect() - // const response = await axios({ - // method: 'GET', - // baseURL: host, - // headers: { - // 'Content-Type': 'application/json', - // 'apikey': globalApiKey - // }, - // url: `/instance/fetchInstances?instanceName=${instanceName}` - // }) - } catch (e) { this.connection.valid = false throw e.response?.data?.response?.message || e.response || e @@ -92,9 +98,24 @@ export const useAppStore = defineStore('app', { async reconnect() { try { const { host, globalApiKey } = this.connection - if (!host || !globalApiKey) { - throw new Error('Invalid connection') + if (!host || !globalApiKey) throw new Error('Invalid connection') + + const apiResponse = await axios({ + method: 'GET', + baseURL: host, + headers: { + 'Content-Type': 'application/json', + 'apikey': globalApiKey + }, + url: '/' + }) + + if (!apiResponse.data || !apiResponse.data.message || !apiResponse.data.message.includes('Evolution API')) { + throw new Error('Essa conexão não é uma instância da evolution-api') } + + const { version } = apiResponse.data + const response = await axios({ method: 'GET', baseURL: host, @@ -105,7 +126,7 @@ export const useAppStore = defineStore('app', { url: '/instance/fetchInstances' }) - this.saveConnection({ host, globalApiKey }) + this.saveConnection({ host, globalApiKey, version }) this.instancesList = response.data } catch (e) { @@ -123,6 +144,13 @@ export const useAppStore = defineStore('app', { this.instancesList[index].instance.status = status }, + setPhoto(instanceName, photo) { + const index = this.instancesList.findIndex( + (instance) => instance.instance.instanceName === instanceName + ) + if (index !== -1) this.instancesList[index].instance.profilePictureUrl = photo + }, + addInstanceKey({ instance, key }) { this.instancesKeys[instance] = key }, @@ -137,11 +165,12 @@ export const useAppStore = defineStore('app', { this.saveLocalStorage() }, - saveConnection({ host, globalApiKey }) { + saveConnection({ host, globalApiKey, version }) { this.connection = { valid: true, host, globalApiKey, + version } const currentKey = this.connectionsList.findIndex( diff --git a/src/views/Home.vue b/src/views/Home.vue index 6cd2153..d104c9b 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,7 +1,7 @@