working bot

This commit is contained in:
3dyuval 2023-04-21 20:57:53 +03:00
parent 53d07a2db5
commit 1ec9a6c90d
9 changed files with 7260 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
.env
.env
node_modules

6
.prettierrc Normal file
View File

@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}

14
dist/index.js vendored Normal file
View File

@ -0,0 +1,14 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const PORT = 3000;
const app = (0, express_1.default)();
app.get('/', (req, res) => {
res.send('Hello!');
});
app.listen(PORT, () => {
console.log(`server is listening on port ${PORT}`);
});

7116
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

27
package.json Normal file
View File

@ -0,0 +1,27 @@
{
"name": "tami-events",
"version": "1.0.0",
"description": "",
"main": "/src/index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon index.ts --watch",
"start": "tsc && pm2 start --name events dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.15.13",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"node-telegram-bot-api": "^0.61.0",
"nodemon": "^2.0.22",
"pm2": "^5.3.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"devDependencies": {
"@types/node-telegram-bot-api": "^0.61.6"
}
}

11
src/eventsRequest.ts Normal file
View File

@ -0,0 +1,11 @@
export const body = JSON.stringify({
query:
'\n query {\n\t\tgroupByUrlname (urlname: "tel-aviv-makers-tami") {\n\t\t\tname\n\t\t\tid \n\t\t\tlogo {\n\t\t\t\tbaseUrl\n\t\t\t}\n\t\t\tmemberships {\n\t\t\t\tcount\n\t\t\t}\n\t\t\t\tupcomingEvents (input: {first: 10}){\n\t\t\t\t\tedges {\n\t\t\t\t\t\tnode {\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\teventUrl\n\t\t\t\t\t\t\tdescription\n# \t\t\t\t\t\t\thost\n# \t\t\t\t\t\t\thostPhoto\n# \t\t\t\t\t\t\timages \n# \t\t\t\t\t\t\tstatus\n# \t\t\t\t\t\t\tdatetime\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n }\n ',
variables: {},
})
export const headers = {
'content-type': 'application/json',
cookie:
'MEETUP_BROWSER_ID=id=963e1243-275b-4e68-a00c-330c5d2a6348; SIFT_SESSION_ID=01f9536e-9629-4ba5-b7e8-dcbb3f2a8e62; _rm=ca3f9819-24d3-4ca9-9035-ab8cddfdf359; _gid=GA1.2.1614206408.1682069567; memberId=233195334; MEETUP_LANGUAGE=language=en&country=US; MEETUP_CSRF=7af445f3-4dab-4a31-be48-e449e717823e; MEETUP_SESSION=e22c3d4f-43eb-4ffa-b8ef-f0042f93272b; MEETUP_MEMBER=id=233195334&status=1&timestamp=1682069648&bs=0&tz=Asia/Jerusalem&zip=meetup2&country=il&city=Tel+Aviv-Yafo&state=&lat=32.07&lon=34.77&ql=false&s=19bc1c85fc1db71bc29c6f9bd93e91b40b4dff0c&scope=ALL&rem=1; ___uLangPref=en_US; _ga=GA1.1.1693828779.1682069567; OptanonConsent=isGpcEnabled=1&datestamp=Fri+Apr+21+2023+12:39:54+GMT+0300+(Israel+Daylight+Time)&version=202211.2.0&isIABGlobal=false&hosts=&consentId=50d8bdc9-1a34-4dcf-991f-43a64e2edba9&interactionCount=1&landingPath=NotLandingPage&groups=C0002:1,C0001:1,C0004:0,C0003:1&AwaitingReconsent=false; _ga_NP82XMKW0P=GS1.1.1682069566.1.1.1682069995.37.0.0',
}

32
src/index.ts Normal file
View File

@ -0,0 +1,32 @@
import express from 'express'
import { body, headers } from './eventsRequest'
import dotenv from 'dotenv'
dotenv.config()
const PORT = process.env.PORT
const app = express()
app.get('/events', (req, res) => {
fetch('https://api.meetup.com/gql', {
method: 'POST',
headers,
body,
})
.then((response) => {
return response.json()
})
.then((events) => {
res.status(200)
res.send(events)
})
.catch((err) => {
res.status(400)
res.send('Something went wrong')
})
})
app.listen(PORT, () => {
console.log(`server is listening on port ${PORT}`)
})

34
src/telegramBot.ts Normal file
View File

@ -0,0 +1,34 @@
import dotenv from 'dotenv'
const TelegramBot = require('node-telegram-bot-api')
dotenv.config()
import { headers, body } from './eventsRequest'
const PORT = process.env.PORT,
token = process.env.TELEGRAM_BOT_TOKEN
const bot = new TelegramBot(token, { polling: true })
bot.onText(/\/events/, (msg, match) => {
const chatId = msg.chat.id
const resp = match[1] // the captured "whatever"
fetch('https://api.meetup.com/gql', {
method: 'POST',
headers,
body,
})
.then((response) => {
return response.json()
})
.then((events) => {
bot.sendMessage(chatId, JSON.stringify(events).substring(0, 90))
})
.catch((err) => {
bot.sendMessage(chatId, 'Something went wrong')
})
})
// bot.on('message', (msg) => {
// const chatId = msg.chat.id;
// bot.sendMessage(chatId, 'Received your message');
// });

18
tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"extends": "ts-node/node16/tsconfig.json",
"ts-node": {
"transpileOnly": true,
"files": true,
},
"compilerOptions": {
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "commonjs", /* Specify what module code is generated. */
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": false, /* Enable all strict type-checking options. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
}
}