First minimal working version!

This commit is contained in:
fadelkon 2022-07-04 17:54:33 +02:00
commit 1308f883a8
5 changed files with 168 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules/
package-lock.json
conf/config.json

4
conf/config.sample.json Normal file
View File

@ -0,0 +1,4 @@
{
"auth_token": "1234567890:ABCDEF-demo-token-ask-bot-father-99",
"chat_id": "-1001234567890"
}

91
data/demo-event.js Normal file
View File

@ -0,0 +1,91 @@
demo_event = {
id: 1,
title: 'Presentació del llibre "Transgresorxs"',
slug: 'presentacio-del-llibre-transgresorxs',
description: '<p>Presentació del llibre "Transgresorxs" a càrrec de Bru Madrenas, en acabat hi haurà kafeta</p>',
multidate: false,
start_datetime: 1657126800,
end_datetime: 1657139400,
image_path: null,
media: [
{
url: '27af5196c795fb4161eebe9c8f7643de.jpg',
height: 800,
width: 566,
name: 'Presentació del llibre "Transgresorxs"',
focalpoint: [Array]
}
],
is_visible: true,
recurrent: null,
likes: [],
boost: [],
createdAt: 2022-07-04T14:54:01.231Z,
updatedAt: 2022-07-04T15:26:41.356Z,
placeId: 1,
userId: 1,
parentId: null,
tags: [
{
tag: 'kafeta',
createdAt: 2022-07-04T15:17:25.301Z,
updatedAt: 2022-07-04T15:17:25.301Z,
event_tags: [Object]
},
{
tag: 'presentació llibre',
createdAt: 2022-07-04T14:54:01.268Z,
updatedAt: 2022-07-04T14:54:01.268Z,
event_tags: [Object]
},
{
tag: 'transfeminisme',
createdAt: 2022-07-04T14:54:01.268Z,
updatedAt: 2022-07-04T14:54:01.268Z,
event_tags: [Object]
}
],
place: {
id: 1,
name: 'Ateneu llibertari la zitzània',
address: 'Carrer Muntanya 96',
createdAt: 2022-07-04T14:54:01.131Z,
updatedAt: 2022-07-04T14:54:01.131Z
},
notifications: [
{
id: 1,
filters: [Object],
email: null,
remove_code: null,
action: 'Create',
type: 'ap',
createdAt: 2022-07-04T14:51:19.265Z,
updatedAt: 2022-07-04T14:51:19.265Z,
event_notification: [Object]
},
{
id: 2,
filters: [Object],
email: null,
remove_code: null,
action: 'Update',
type: 'ap',
createdAt: 2022-07-04T14:51:19.265Z,
updatedAt: 2022-07-04T14:51:19.265Z,
event_notification: [Object]
}
],
user: {
id: 1,
settings: [],
email: 'admin',
description: null,
password: '$2a$10$RzEuxb.thisisprotectedbuthuh.anywayyoudontneeditdoyou",
recover_code: null,
is_admin: true,
is_active: true,
createdAt: 2022-07-04T14:51:36.834Z,
updatedAt: 2022-07-04T14:51:36.834Z
}
}

56
index.js Normal file
View File

@ -0,0 +1,56 @@
const { Telegraf } = require('telegraf')
const config = require("./conf/config.json")
const chid = config.chat_id;
const bot = new Telegraf(config.auth_token);
const photo_url = "https://gancio.org/assets/gancio.png";
const plugin = {
gancio: null,
load (gancio) {
plugin.gancio = gancio
bot.telegram.sendMessage(chid, "hola :D");
bot.telegram.sendPhoto(chid, photo_url, {caption: "una foto!" });
},
onEventCreate (event) {
const eventLink = `${plugin.gancio.settings.baseurl}/event/${event.slug}`
if (!event.is_visible) {
console.error(`Unconfirmed event created: ${event.title} / ${eventLink}`)
} else {
console.error(`Event created: ${event.title} / ${eventLink}`)
}
notifyEvent(event);
},
onEventUpdate (event) {
console.error(`Event "${event.title}" updated`)
console.error(event)
notifyEvent(event);
},
onEventDelete (event) {
console.error(`Event "${event.title}" deleted`)
console.error(event)
}
}
function renderEvent(event) {
return `\
<b>${event.title}</b>
📅 ${(new Date(event.start_datetime*1000)).toLocaleString()}
📌 ${event.place.name}
${event.description.replace(/<p>/g,"").replace(/<\/p>/, "\n")}
${event.tags.reduce((x, y) => { return x+" #"+y.tag.replaceAll(" ", "_") }, "").trim()}
<a href="https://bcn.convoca.la">🔥 bcn.convoca.la 🍀</a>
<a href="https://bcn.convoca.la/api/event/presentacio-del-llibre-transgresorxs-1.ics">Afegeix al calendari</a>
`
}
function notifyEvent(event) {
console.error(event);
bot.telegram.sendPhoto(chid, photo_url, {"parse_mode": "HTML", "caption": renderEvent(event)});
}
module.exports = plugin

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "gancio-plugin-telegram",
"version": "0.1.0",
"description": "Telegram bridge plugin for Gancio",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "AGPL-3.0-or-later",
"dependencies": {
"telegraf": "^4.8.5"
}
}