Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from shampiniony/feature/frnt-27-create-a-join-…
Browse files Browse the repository at this point in the history
…command-with-custom-coords

Feature/frnt-27-create-a-join-command-with-custom-coords
  • Loading branch information
mikedegeofroy authored Sep 2, 2024
2 parents abf49cd + cc42218 commit 2b1ff9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
Binary file added public/cover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 41 additions & 10 deletions routes/dashBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ router.post(`/hook`, (req, res) => {
if (req.body.message) {
let message = req.body.message;
let chat_id = message.chat.id;

console.log(sessionStates[chat_id])

if (!sessionStates[chat_id]) {
sessionStates[chat_id] = { reportMode: false };
Expand All @@ -90,14 +88,20 @@ router.post(`/hook`, (req, res) => {
currentSession.reportMode = false;

if (report_chat_id === undefined) {
console.log("`report_chat_id` is undefined. Check envs to turn on reports.");
console.log(
'`report_chat_id` is undefined. Check envs to turn on reports.'
);
} else {
let reportTime = new Date().toLocaleString();

sendMessage(
{
chat_id: reportChatId,
text: `⚠️ <b>Репорт от пользователя:</b>\n\n<b>Имя:</b> ${message.from.first_name} ${message.from.last_name || ''}\n<b>Юзернейм:</b> @${message.from.username || 'нет юзернейма'}\n<b>Chat ID:</b> ${chat_id}\n<b>Время обращения:</b> ${reportTime}\n\n<b>Сообщение:</b>\n${text}`,
text: `⚠️ <b>Репорт от пользователя:</b>\n\n<b>Имя:</b> ${
message.from.first_name
} ${message.from.last_name || ''}\n<b>Юзернейм:</b> @${
message.from.username || 'нет юзернейма'
}\n<b>Chat ID:</b> ${chat_id}\n<b>Время обращения:</b> ${reportTime}\n\n<b>Сообщение:</b>\n${text}`,
parse_mode: 'HTML',
},
'sendMessage',
Expand All @@ -118,7 +122,7 @@ router.post(`/hook`, (req, res) => {
if (message.from.last_name) {
fullName += ` ${message.from.last_name}`;
}

sendMessage(
{
chat_id: chat_id,
Expand All @@ -128,6 +132,34 @@ router.post(`/hook`, (req, res) => {
'sendMessage',
token
);
} else if (text.split(' ')[0] === '/join') {
axios
.post(`${api_url}/api/v1/lobbies`, {
location: {
lat: Number(text.split(' ')[1]),
lon: Number(text.split(' ')[2]),
},
})
.then((data) => {
sendMessage(
{
chat_id: chat_id,
text: `Не знаете, куда пойти? Давайте подберем вам место! (инвайт в комнату ${data.data.id})`,
reply_markup: {
inline_keyboard: [
[
{
text: 'В лобби!',
url: `https://t.me/${bot_username}/app?startapp=${data.data.id}`,
},
],
],
},
},
null, // Set `ep` to null to use 'sendMessage' endpoint
token
);
});
} else if (text === '/help') {
sendMessage(
{
Expand All @@ -142,6 +174,7 @@ router.post(`/hook`, (req, res) => {
sendMessage(
{
chat_id: chat_id,
photo_url: `${bot_url}/cover.jpg`,
text: 'Теперь отправьте сообщение, которое вы хотите сообщить администрации.',
},
'sendMessage',
Expand All @@ -159,7 +192,6 @@ router.post(`/hook`, (req, res) => {
}
}
}


if (req.body.inline_query) {
let q = req.body.inline_query;
Expand All @@ -185,8 +217,7 @@ router.post(`/hook`, (req, res) => {
} else {
let coords = q.location;
axios
.post(`${api_url}/api/v1/lobbies/find`, {
dist: 10,
.post(`${api_url}/api/v1/lobbies`, {
location: {
lat: coords.latitude,
lon: coords.longitude,
Expand All @@ -200,12 +231,12 @@ router.post(`/hook`, (req, res) => {
{
type: `photo`,
id: `app2`,
photo_url: `${bot_url}/images/dash/cover.jpg`,
photo_url: `${bot_url}/cover.jpg`,
title: data.data.id,
description: `Приглашение в комнату ${data.data.id}`,
is_personal: false,
caption: `Не знаете, куда пойти? Давайте подберем вам место! (инвайт в комнату ${data.data.id})`,
thumbnail_url: `${bot_url}/dash/cover.jpg`,
thumbnail_url: `${bot_url}/cover.jpg`,
reply_markup: {
inline_keyboard: [
[
Expand Down

0 comments on commit 2b1ff9b

Please sign in to comment.