Xenon-s / ioBroker.device-reminder

Notifications at device start or end by telegram, Alexa, Whatsapp, sayit, pushover, email
MIT License
27 stars 8 forks source link

discord zum Versand der Nachrichten ermöglichen #341

Closed GuSchmi closed 8 months ago

GuSchmi commented 10 months ago

Bitte discord als Benachrichtigungs-Kanal implementieren. Danke.

Xenon-s commented 8 months ago

Screenshot_20240115_193511_Chrome

@GuSchmi Welche Daten werden benötigt, damit die Nachricht auch sicher ankommt?

GuSchmi commented 8 months ago

Einem Blockly-Skript kann ich folgendes entnehmen wobei 'DiscordUser' eine Variable ist:

    await new Promise((resolve) => {
                const content = 'WaMa gestartet ...';

          if (typeof content === 'object') {
            // remove empty content
            if (content.hasOwnProperty('content') && !content.content) {
              delete content.content;
            }

            // check files
            if (content.files) {
              if (!Array.isArray(content.files)) {
                content.files = [content.files];
              }
              for (let i = 0; i < content.files.length; i++) {
                if (typeof content.files[i] === 'object') {
                  if (!content.files[i].name) {
                    content.files[i].name = content.files[i].attachment.split(/[\/]/).pop();
                  }
                } else {
                  content.files[i] = {
                    attachment: content.files[i],
                    name: content.files[i].split(/[\/]/).pop(),
                  };
                }
              }
            }

            // check embeds
            if (content.embeds) {
              if (!Array.isArray(content.embeds)) {
                content.embeds = [content.embeds];
              }
              for (let i = 0; i < content.embeds.length; i++) {
                if (typeof content.embeds[i] === 'object') {
                  for (const n of ['title', 'description', 'url']) {
                    if (!content.embeds[i].hasOwnProperty(n) && !content.embeds[i][n]) {
                      delete content.embeds[i][n];
                    }
                  }
                } else {
                  content.embeds[i] = {
                    description: content.embeds[i],
                  };
                }
              }
            }
          }

          sendTo('discord.0', 'sendMessage', {
            userName: DiscordUser,

            content: content,

          }, (result) => {
            if (result.error) {
              log(`[discord.0] sendTo error: ${result.error}\n${JSON.stringify(result)}`, 'warn');
              resolve();
              return;
            }

            resolve();
          });
        });

Hilft das weiter?

Xenon-s commented 8 months ago

Es gibt ja die Möglichkeit userID, userTag, userName, sowieso ServerID und channelID anzugeben. In dem Skript wird nur der userName genutzt. Wenn das reicht um die Nachricht sicher zu bekommen, baue ich den userName als Pflicht ein, alles andere optional

GuSchmi commented 8 months ago

Hört sich gut an. Im Blockly-Block sieht es so aus, als ob 'userID', 'userTag' und 'Tag' exclusivODER verknüpft wären: grafik

Xenon-s commented 8 months ago

Ich hau gleich mal in die Tasten und geb dir bescheid

Xenon-s commented 8 months ago

ist online, aber nur auf github! Da es eine beta auf github ist, werden dir im Log mit Sicherheit einige Log Meldungen angezeigt, solange sie nur Level info sind, kannst du sie ignorieren

GuSchmi commented 8 months ago

Eben mit hinterlegtem 'Username' erfolgreich getestet :-) Vielen Dank für die rasche Umsetzung!