Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Which javascript version on SDK?

    Developers
    3
    8
    965
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • flic 16
      flic 16 last edited by

      I'm having some trouble building a basic script that sends sms alerts stored on the flichub.

      What javascript version is used in this environment for HBACE27-27526
      Firmware: 4.2.14

      Emil 1 Reply Last reply Reply Quote 0
      • Emil
        Emil FlicTeam @gregor.vilkner last edited by

        @gregor-vilkner yes! Can you tell me a bit more about your use cases?

        1 Reply Last reply Reply Quote 0
        • gregor.vilkner
          gregor.vilkner @Emil last edited by

          @Emil fantastic! the other new sdk features will include twist support? we have lots of use cases where the twist would be dialed to coded manufacturing activities...

          Emil 1 Reply Last reply Reply Quote 0
          • Emil
            Emil FlicTeam @gregor.vilkner last edited by

            @gregor-vilkner we are working on upgrading the JS engine to the newer QuickJS which has ES2023 support. Currently we are doing internal testing and will probably release it in a few months together with other new features to the hub sdk.

            gregor.vilkner 1 Reply Last reply Reply Quote 0
            • gregor.vilkner
              gregor.vilkner @Emil last edited by gregor.vilkner

              @Emil a few "first flic-day" observations on this topic:

              • we're trying to integrate with a GraphQL api and need to turn all our beautiful queries into one-liners. is there no support for 'let', '``', multi-line text, and text substitutions?
                let query = query q1{ heroes(name: ${someName}){ name father{ name } } };

              • is there any async await way of doing web requests without call-back hell? it's like going back to 1998...

              • no fetch?

              • no atob(), no jwt decoding

              function isTokenExpired(token) {
              if(token==null) return true;
              const arrayToken = token.split('.');
              const part2 = JSON.parse(new TextDecoder().decode(Duktape.dec('base64', arrayToken[1])));
              return Math.floor(new Date().getTime() / 1000) >= part2.sub;
              }

              Emil 1 Reply Last reply Reply Quote 0
              • Emil
                Emil FlicTeam @flic 16 last edited by Emil

                @flic-16 said in Which javascript version on SDK?:

                Buffer.from is a Node.js specific feature not present in any javascript/ecmascript standard.

                You can use Duktape.enc('base64', 'some string') instead to perform the Base64 encode.

                Like this:

                const EncodedAuth = Duktape.enc('base64', 'abcd123:Password!');
                
                1 Reply Last reply Reply Quote 0
                • flic 16
                  flic 16 @Emil last edited by

                  @Emil said in Which javascript version on SDK?:

                  old javascript version

                  Is it possible to have a javascript in this environment send an SMS to the smsburst API?

                  We have it working in other environments, but this one just doesnt seem to work.

                  const http = require('http');
                  
                  // Basic authentication credentials
                  const encodedAuth = Buffer.from('abcd123:Password123!').toString('base64');
                  
                  // Setting up the headers for the request
                  const headers = {
                      "Authorization": "Basic " + encodedAuth
                  };
                  
                  // Message details
                  const message = encodeURIComponent("IVONNE: Testing from Flic SDK");
                  const to = encodeURIComponent("+16475551212");
                  const senderNumber = encodeURIComponent("18335551212");
                  const repliesToEmail = encodeURIComponent("email@example.com");
                  
                  // Constructing the URL
                  const url = "https://api.transmitsms.com/send-sms.json?message=" + message + "&to=" + to + "&from=" + senderNumber + "&replies_to_email=" + repliesToEmail;
                  
                  // Making the HTTP request
                  function sendSmsViaTransmitSms() {
                      console.log("Starting request to SMS Burst API...");
                  
                      http.makeRequest({
                          url: url,
                          method: 'POST',
                          headers: headers
                      }, function(error, result) {
                          if (error) {
                              console.error("An error occurred during the HTTP request:", error);
                          } else {
                              console.log("Received response from SMS Burst API");
                              console.log("Response status code:", result.statusCode);
                              console.log("Response headers:", result.headers);
                  
                              // Check if result.content exists and log it
                              if (typeof result.content !== 'undefined') {
                                  console.log("Response body:", result.content);
                              } else {
                                  console.log("Response body not available in this format");
                              }
                          }
                      });
                  }
                  
                  // Execute the function to send the SMS
                  sendSmsViaTransmitSms();
                  

                  Error is:

                  TypeError: undefined not callable (property 'from' of [object Function])
                  at [anon] (duk_js_call.c:2917) internal
                  at [anon] (root/basicBurstSMSTest/main.js:1)
                  at require (init.js:131)
                  at [anon] (init.js:139) preventsyield
                  at runInit () native strict preventsyield
                  at handlePacket (pipe_communication.js:48)
                  at readCallback (pipe_communication.js:93) preventsyield

                  Emil 1 Reply Last reply Reply Quote 0
                  • Emil
                    Emil FlicTeam @flic 16 last edited by

                    @flic-16 currently we use https://duktape.org/ which implements a pretty old javascript version. We might upgrade in the future to an engine supporting a more modern javascript version.

                    flic 16 gregor.vilkner 2 Replies Last reply Reply Quote 0
                    • First post
                      Last post