Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Telegram ask beantwortet sich nach 10 -15 Sekunden selbst

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Telegram ask beantwortet sich nach 10 -15 Sekunden selbst

    This topic has been deleted. Only users with topic management privileges can see it.
    • Peoples
      Peoples last edited by Peoples

      Hallo zusammen,

      ich schicke mir aus verschiedenen Scripts Fragen über Telegram, welche ich dann mit Ja/Nein beantworten kann, im Adapter habe ich es so eingestellt dass die Frage ein Timeout von 5 Minuten hat.

      Seltsamer Weise beantwortet sich die Frage jedoch nach ca. 10 bis 15 Sekunden mit Nein selbst.
      Meine Vermutung ist, dass es irgendwie mit dem async zusammen hängen muss nur stecke ich da nicht so tief drin um mir sicher zu sein, denn wenn ich die Frage wie in der Doku auslöse, passiert das nicht.

      Hier der Aufruf wie in der Doku:

      sendTo('telegram.0', 'ask', {
          text: 'Are you sure?',
          reply_markup: {
              inline_keyboard: [
                  // two buttons could be on one line too, but here they are on different
                  [{ text: 'Yes!',  callback_data: '1' }], // first line
                  [{ text: 'No...', callback_data: '0' }]  // second line
              ]
          }
      }, msg => {
          console.log('user says ' + msg.data);
      });
      

      Und hier wie ich sie nutze:

      async function questionContent(dp){
              var content = {};
              switch(dp) {
                  case 'lichtbuero':
                      content.question = 'Möchtest Du das Licht im Büro einschalten';
                      content.chatId = '222222222222';
                      content.aw1 = 'Das Licht wird eingeschalten';
                      content.aw2 = 'Die Antwort war Nein';
                      content.switchUnit ='hm-rpc.0.OEQ1228041.1.STATE';
                      content.switchValue = true;
                      return (content);
      
                  case 'vacuumCleaner_0_On':
                      content.question = 'Der Sauger im Erdgeschoss ist heute noch nicht gefahren, möchtest du ihn einschalten?';
                      content.chatId = 'all';
                      content.aw1 = 'Der Saugrobotter im Erdgeschoss wird eingeschalten';
                      content.aw2 = 'Die Antwort war Nein';
                      content.switchUnit ='0_userdata.0.VacuumRobots.0.Vacuuming_ON-OFF-Switch';
                      content.switchValue = true;
                      return (content);
                 
                  case 'vacuumCleaner_1_On':
                      content.question = 'Der Sauger im Keller ist heute noch nicht gefahren, möchtest du ihn einschalten?';
                      content.chatId = 'all';
                      content.aw1 = 'Der Saugrobotter im Keller wird eingeschalten';
                      content.aw2 = 'Die Antwort war Nein';
                      content.switchUnit ='0_userdata.0.VacuumRobots.1.Vacuuming_ON-OFF-Switch';
                      content.switchValue = true;
                      return (content);
              }
      }
      
      async function sendQuestion(dp){
          try{
              var content = await questionContent(dp);
      
              if(content.chatId == 'all'){
                  sendTo('telegram.0', 'ask', {
                      text: content.question,
                      reply_markup: {
                          inline_keyboard: [
                              [{ text: 'Ja',  callback_data: 'y' }, { text: 'Nein', callback_data: 'n' }]
                          ]
                      }
                  }, msg => {    
                      // Auf die Antwort reagieren
                      if ( msg.data == 'y' ) {
                          sendTo("telegram.0", "send", { text: content.aw1});
                          if(content.switchUnit != '') setState(content.switchUnit, content.switchValue);
                      } else {
                          sendTo("telegram.0", "send", { text: content.aw2});
                      }       
                  });
              } else {
                  sendTo('telegram.0', 'ask', {
                      text: content.question,
                      chatId: content.chatId,
                      reply_markup: {
                          inline_keyboard: [
                              [{ text: 'Ja',  callback_data: 'y' }, { text: 'Nein', callback_data: 'n' }]
                          ]
                      }
                  }, msg => {    
                      // Auf die Antwort reagieren
                      if ( msg.data == 'y' ) {
                          sendTo("telegram.0", "send", { text: content.aw1,chatId: content.chatId});
                          if(content.switchUnit != '') setState(content.switchUnit, content.switchValue);
                      } else {
                          sendTo("telegram.0", "send", { text: content.aw2,chatId: content.chatId});
                      }       
                  });
              }
          } catch (error) {
              log('Fehler bei Funktion sendQuestion');
          }
      };
      
      

      Vielleicht hat jemand eine Idee woran das liegen kann, Tipps sind herzlich willkommen.

      Peoples 1 Reply Last reply Reply Quote 0
      • Peoples
        Peoples @Peoples last edited by

        Vielleicht einer von den Profis eine Idee bzw. einen Ansatz?

        @paul53 , @haus-automatisierung ?

        haus-automatisierung 1 Reply Last reply Reply Quote 0
        • haus-automatisierung
          haus-automatisierung Developer Most Active @Peoples last edited by

          @peoples Es gibt einen Timeout wie lange man Zeit hat zu antworten. Kann man auf der Instanz konfigurieren.

          Es wird also nicht mit nein geantwortet, sondern einfach nur der else Teil wegen des Timeouts ausgeführt

          Peoples 1 Reply Last reply Reply Quote 0
          • Peoples
            Peoples @haus-automatisierung last edited by Peoples

            @haus-automatisierung
            Hi, das habe ich gesehen, aber der Timeout steht auf:
            sc.JPG

            Und abgebrochen wird nach ca. 10 -15 Sekunden, deswegen wundert es mich ja

            Peoples 1 Reply Last reply Reply Quote 0
            • Peoples
              Peoples @Peoples last edited by

              @haus-automatisierung

              Hast du als Mitentwickler auf git evtl. Eine Lösungsidee? Bzw. funktioniert das bei dir fehlerfrei?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Support us

              ioBroker
              Community Adapters
              Donate

              1.0k
              Online

              31.7k
              Users

              79.7k
              Topics

              1.3m
              Posts

              2
              5
              295
              Loading More Posts
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes
              Reply
              • Reply as topic
              Log in to reply
              Community
              Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
              The ioBroker Community 2014-2023
              logo