Skip to content

Commit

Permalink
activity summary
Browse files Browse the repository at this point in the history
  • Loading branch information
qertis committed Sep 25, 2024
1 parent e91ee3c commit 3091094
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"minimist": "1.2.8",
"request-json-rpc2": "2.2.3",
"snyk": "1.1243.0",
"telegram-bot-activitystreams": "1.0.5",
"telegram-bot-activitystreams": "1.0.6",
"telegram-bot-api-express": "1.3.4",
"uuid": "10.0.0"
},
Expand Down
7 changes: 3 additions & 4 deletions src/actions/system/help.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getCheckSum = (buffer, algorithm = 'md5', encoding = 'hex') => {
module.exports = async (bot, message) => {
const helpData = Object.entries({
help: 'Помощь',
ping: 'Ping',
ping: 'Проверка связи',
// eslint-disable-next-line
}).reduce((accumulator, [command, description]) => {
accumulator['/' + command.toLowerCase()] = description;
Expand All @@ -29,15 +29,14 @@ module.exports = async (bot, message) => {
accumulator += result;
return accumulator;
}, '') +
'\n' + package_.name + ': ' + packageLock_.version +
'\nF.A.Q.: ' +
package_.homepage +
'/faq/' +
'\nVERSION: ' +
packageLock_.version +
'\nCHECKSUM: ' +
getCheckSum(JSON.stringify(packageLock_));

const string_ = `Используй команды:\n ${commandsReadable}`;
const string_ = `Используйте команды:\n ${commandsReadable}`;
await bot.sendMessage(message.chat.id, string_, {
disable_notification: true,
disable_web_page_preview: true,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/generate-calendar.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports.generateCalendar = async ({ id, activity, jwt, language }) => {
},
jwt: jwt,
headers: {
Accept: 'text/calendar',
'Accept': 'text/calendar',
'Accept-Language': language,
},
});
Expand Down
26 changes: 17 additions & 9 deletions src/libs/dialog.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Dialog {
this._uid = uuidv1();
this.messages = [];
this.activity = {
'@context': ['https://www.w3.org/ns/activitystreams'],
'@context': ['https://www.w3.org/ns/activitystreams',
{
'@language': 'ru', // todo пока используем только русский
}],
'summary': '',
'type': 'Collection',
'totalItems': 0,
Expand All @@ -31,15 +34,15 @@ class Dialog {
*/
async push(message) {
const activity = activitystreams(message);
// this.language = message.from.language_code;
this.language = 'ru'; // todo пока используем только русский
activity.type = 'Activity';
this.language = message.from.language_code;

if (message.voice) {
const response = await fetch(message.voice.file.url);
const arrayBuffer = await response.arrayBuffer();
const [{ queryResult }] = await this.voice(Buffer.from(arrayBuffer));
this.language = queryResult.languageCode;
activity.type = 'Activity'; // todo - обучить DialogFlow возвращать Intents с содержанием из списка: https://www.w3.org/TR/activitystreams-vocabulary/#h-types
activity.summary = queryResult.intent.displayName;
switch (queryResult.intent.displayName) {
default: {
activity.object = [
Expand All @@ -54,7 +57,7 @@ class Dialog {
}
} else if (message.text) {
const [{ queryResult }] = await this.text(message.text);
activity.type = 'Activity'; // todo - обучить DialogFlow возвращать Intents с содержанием из списка: https://www.w3.org/TR/activitystreams-vocabulary/#h-types
activity.summary = queryResult.intent.displayName;
this.language = queryResult.languageCode;
} else if (message.photo) {
} else if (message.location) {
Expand All @@ -74,6 +77,7 @@ class Dialog {
if (message.location.caption) {
const [{ queryResult }] = await this.text(message.location.caption);
this.language = queryResult.languageCode;
activity.summary = queryResult.intent.displayName;
activity.object.push({
type: 'Note',
content: message.location.caption,
Expand All @@ -91,6 +95,8 @@ class Dialog {
}
this.activity.totalItems++;
this.activity.items.push(activity);

return activity;
}
/**
* @returns {string}
Expand All @@ -99,10 +105,12 @@ class Dialog {
return this._uid;
}
set language(languageCode) {
// todo - добавлять только если такого еще нет в списке
this.activity['@context'].push({
'@language': languageCode,
});
const hasLang = this.activity['@context'].some(c => (c && c['@language'] === languageCode))
if (!hasLang) {
this.activity['@context'].push({
'@language': languageCode,
});
}
}
/**
* @returns {string}
Expand Down

0 comments on commit 3091094

Please sign in to comment.