Minor localisation and usability bugfixes

When the server's locale and/or timezone are different from that in
Gancio, weird things were happening.

While there, we make `renderEvent` a tad more modular so that
potentially new settings can be introduced in the future.

Introduced changes:

- `renderEventDateTime` uses both Gancio's locale and timezone, this
  has the effect that (in theory! please test) no matter the server's
  timezone, the message will be rendered according to Gancio's
  settings (which is, I'd argue, an admin's expectation)
- `renderEventTitle` generates a link to Gancio's event, which people
  can use to get more info
- I noticed while importing events that sometimes the `description`
  field could be prefilled with `null` as a string, while this might
  be a Gancio bug to fix, we can also skip those descriptions

New boolean configuration options:
- `skip_link_to_gancio`: it skips the final link to Gancio making the
  message slightly shorter
- `tags_link_to_gancio`: it affects `renderEventTags`, which by
  default allows Telegram to handle tags. When this option is applied,
  tags link instead to their Gancio site, which lists all related
  events on the instance
This commit is contained in:
Evilham 2023-05-30 15:43:52 +02:00
parent 971ea23b6a
commit dc0db05d07
Signed by: evilham
GPG Key ID: AE3EE30D970886BF
2 changed files with 60 additions and 6 deletions

View File

@ -1,4 +1,6 @@
"auth_token": "1234567890:ABCDEF-demo-token-ask-bot-father-99",
"chat_id": "-1001234567890"
"chat_id": "-1001234567890",
"skip_link_to_gancio": false,
"tags_link_to_gancio": false

View File

@ -24,6 +24,16 @@ const plugin = {
description: 'Channel id',
required: true,
hint: 'The <strong>channel/group id</strong> where to publish the messages.<br/><a href="https://github.com/GabrielRF/telegram-id">Help on getting chat ids</a>'
skip_final_link_to_gancio: {
type: 'CHECK',
description: 'Skip the final link to Gancio',
hint: "By default a link with Gancio's title will be added to each event. When checked, it is skipped"
tags_link_to_gancio: {
type: 'CHECK',
description: 'Tags link to Gancio instead of being handled in Telegram',
hint: "By default an event's tags will be handled by Telegram. When checked, they link to the tag on Gancio"
@ -113,6 +123,7 @@ function cleanHtml(html) {
function renderPlace(place) {
// TODO: It might make sense to have a link to other events in the same place?
if (place.longitude && place.latitude) {
return `<a href="https://www.openstreetmap.org/?mlat=${place.latitude}&mlon=${place.longitude}#map=19/${place.latitude}/${place.longitude}">${place.name}</a>`
} else {
@ -120,14 +131,55 @@ function renderPlace(place) {
function renderEventTitle(event) {
// I think this makes sense, but linking could be optional
const eventLink = `${plugin.gancio.settings.baseurl}/event/${event.slug}`
return `<b><a href="${eventLink}">${event.title}</a></b>`
function renderEventDescription(event) {
// In certain cases, imported events have description 'null' (as string)
if (event.description && event.description !== "null") {
return `\n${cleanHtml(event.description)}\n`
return ""
function renderEventDateTime(event) {
// I think this should be correct(!) please test with different server timezones
const eventTime = new Date(event.start_datetime * 1000)
const localeGancio = plugin.gancio.settings.instance_locale
const tzGancio = plugin.gancio.settings.instance_timezone
const dateFormat = { timeZone: tzGancio }
const timeFormat = { hour: "2-digit", minute: "2-digit", ...dateFormat }
return `📅 ${eventTime.toLocaleDateString([localeGancio], dateFormat)}${eventTime.toLocaleTimeString([localeGancio], timeFormat)}`
function renderEventTag(tag) {
const tagText = tag.tag.replaceAll(" ", "_")
if (plugin.settings.tags_link_to_gancio)
return `<a href="${plugin.gancio.settings.baseurl}/tag/${tag.tag}">#${tagText}</a>`
return `#${tagText}`
function renderEventTags(event) {
return event.tags.reduce((x, y) => { return `${x} ${renderEventTag(y)}` }, "").trim()
function renderGancioSite() {
if (plugin.settings.skip_final_link_to_gancio)
return "";
return `<a href="${plugin.gancio.settings.baseurl}">${plugin.gancio.settings.title}</a>`
function renderEvent(event) {
return `\
${event.description? "\n" + cleanHtml(event.description) + '\n' : ""}
📅 ${(new Date(event.start_datetime * 1000)).toLocaleDateString()} ${(new Date(event.start_datetime * 1000)).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}
📌 ${renderPlace(event.place)}
${event.tags.reduce((x, y) => { return x + " #" + y.tag.replaceAll(" ", "_") }, "").trim()}
<a href="${plugin.gancio.settings.baseurl}">${plugin.gancio.settings.title}</a>