Skip to content

Commit

Permalink
feat: проверка /scerarios.yml по умолчанию отключена
Browse files Browse the repository at this point in the history
Ломало стандартное поведение yandex-dialogs-sdk
  • Loading branch information
popstas committed Feb 27, 2019
1 parent 233181d commit 47daf24
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
17 changes: 17 additions & 0 deletions components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
></el-switch>
</el-row>

<el-row>
<el-switch
active-text="Использовать /scenarios.yml"
v-model="isScenarios"
></el-switch>
</el-row>

<el-row>
<el-switch
active-text="Показывать тесты внизу"
Expand Down Expand Up @@ -98,6 +105,7 @@ import "vue-awesome/icons/brands/github";
import {
SET_IS_BOTTOM_TESTS,
SET_IS_PROXY,
SET_IS_SCENARIOS,
SET_IS_CONSOLE_REQUESTS,
SET_MESSAGE_LIMIT,
SET_MESSAGE_STORE_LIMIT,
Expand All @@ -123,6 +131,15 @@ export default {
}
},
isScenarios: {
get() {
return this.$store.state.settings.isScenarios;
},
set(val) {
this.$store.commit(`settings/${SET_IS_SCENARIOS}`, val);
}
},
isBottomTests: {
get() {
return this.$store.state.settings.isBottomTests;
Expand Down
80 changes: 41 additions & 39 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const actions = {

commit(ADD_MESSAGE, {
text: responseData.response.text,
card: responseData.response.card || {header:{},items:[]},
card: responseData.response.card || { header: {}, items: [] },
buttons: responseData.response.buttons,
end_session: responseData.response.end_session,
author: 'Робот',
Expand Down Expand Up @@ -305,50 +305,52 @@ export const actions = {
dispatch(ALICE_REQUEST, '');

// scenarios.yml
try {
const responseData = await this.$axios.$get(state.webhookURL + '/scenarios.yml');
const doc = yaml.safeLoad(responseData);

let tests = [];
let buttons = [];
for (let name in doc) {
const dialog = {
name: name,
messages: doc[name]
};
tests.push(dialog);
if (state.settings.isScenarios) {
try {
const responseData = await this.$axios.$get(state.webhookURL + '/scenarios.yml');
const doc = yaml.safeLoad(responseData);

let tests = [];
let buttons = [];
for (let name in doc) {
const dialog = {
name: name,
messages: doc[name]
};
tests.push(dialog);
buttons.push({
title: name,
payload: JSON.stringify({ scenarios_test: [dialog] })
});
}
commit(SET_TESTS, tests);

buttons.push({
title: name,
payload: JSON.stringify({ scenarios_test: [dialog] })
title: 'все тесты',
payload: JSON.stringify({ scenarios_test: tests })
});
}
commit(SET_TESTS, tests);

buttons.push({
title: 'все тесты',
payload: JSON.stringify({ scenarios_test: tests })
});

commit(ADD_MESSAGE, {
text:
'У навыка есть scenarios.yml, в нем есть следующие сценарии (' +
state.tests.length +
'):',
buttons: state.settings.isBottomTests ? [] : buttons,
author: 'Клиент',
class: 'info'
});
} catch (err) {
//console.error(err);
// it's normal
if (typeof err == 'object' && err.name == 'YAMLException') {
console.log(err);
commit(ADD_MESSAGE, {
text: 'Ошибка в scenarios.yml: ' + err.message,
buttons: [],
text:
'У навыка есть scenarios.yml, в нем есть следующие сценарии (' +
state.tests.length +
'):',
buttons: state.settings.isBottomTests ? [] : buttons,
author: 'Клиент',
class: 'error'
class: 'info'
});
} catch (err) {
//console.error(err);
// it's normal
if (typeof err == 'object' && err.name == 'YAMLException') {
console.log(err);
commit(ADD_MESSAGE, {
text: 'Ошибка в scenarios.yml: ' + err.message,
buttons: [],
author: 'Клиент',
class: 'error'
});
}
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions store/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const SET_IS_BOTTOM_TESTS = 'SET_IS_BOTTOM_TESTS';
export const SET_IS_PROXY = 'SET_IS_PROXY';
export const SET_IS_SCENARIOS = 'SET_IS_SCENARIOS';
export const SET_IS_CONSOLE_REQUESTS = 'SET_IS_CONSOLE_REQUESTS';
export const SET_MESSAGE_LIMIT = 'SET_MESSAGE_LIMIT';
export const SET_MESSAGE_STORE_LIMIT = 'SET_MESSAGE_STORE_LIMIT';
Expand All @@ -9,6 +10,7 @@ export const state = () => ({
isBottomTests: false,
isProxy: process.env.isProxy,
isConsoleRequests: false,
isScenarios: false,
messageLimit: 200, // никогда не может быть больше этого
messageStoreLimit: 20, // после обновления страницы
timeout: 1500
Expand All @@ -21,6 +23,9 @@ export const mutations = {
[SET_IS_PROXY](state, isProxy) {
state.isProxy = isProxy;
},
[SET_IS_SCENARIOS](state, isScenarios) {
state.isScenarios = isScenarios;
},
[SET_IS_CONSOLE_REQUESTS](state, isConsoleRequests) {
state.isConsoleRequests = isConsoleRequests;
},
Expand Down

0 comments on commit 47daf24

Please sign in to comment.