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

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');
// });