Testing a Message Handler Custom Function

Testing a Message Handler Custom Function

While creating a message handler custom function, you can test the function to see if the desired output is received. For testing, you can provide the expected value and see if the expected output value is obtained.

For the message handler custom function, you can test two types of message inputs: Device Message and Device connection Status.

Here is the sample code that comes pre-populated in the code editor when you create a message handler custom function.
  1. headerMap = header.toMap();
  2. deviceid = headerMap.get("deviceid");
  3. receivedtime = headerMap.get("occurred_timestamp");
  4. topic = headerMap.get("topic");
  5. communication_status_flag = headerMap.get("data_internal"); 
  6. if(communication_status_flag == false && topic == "telemetry") { payload = message.toMap(); if(payload.containKey("data"))                 {
    deviceMessage = payload.get("data");
                   }
    else                {
    deviceMessage = payload;
                   }
    else if(communication_status_flag == true) { deviceMessage = Map(); } return deviceMessage;
The above stated code directly fetches data from the payload of the incoming message and returns it as the output. First, we'll test to see if the code works as intended.
  1. Click the Save and Execute button in the top right. This will open the Execute Function dialogue box.



  2. Select Device Message in the Message Type field.
  3. Provide {'temp':25} in the Message field.
  4. Provide any value as Device ID since it is only for testing purpose.
  5. Click Save.
The function will now be executed and the value {'temp':25} will be displayed as the output.


Now, we will handle the incoming data by adding 5 to the message value and test the code.

Add the following line of code inside the else statement while handling the payload.
  1. new_temp = payload.get('temp')+5;
  2. deviceMessage = Map();
  3. deviceMessage.put('temp', new_temp);


Updated Code
:

  1. headerMap = header.toMap();
  2. deviceid = headerMap.get("deviceid");
  3. receivedtime = headerMap.get("occurred_timestamp");
  4. topic = headerMap.get("topic");
  5. communication_status_flag = headerMap.get("data_internal");
  6. if(communication_status_flag == false && topic == "telemetry") { payload = message.toMap(); if(payload.containKey("data")) { deviceMessage = payload.get("dat } else { new_temp = payload.get('temp')+5; deviceMessage = Map(); deviceMessage.put('temp', new_temp); } else if(communication_status_flag == true) { deviceMessage = Map(); }
  7. return deviceMessage;


Once the code is updated,

  1. Click Save and Execute in the top right.

  2. Select Device Message in the Message Type field.

  3. Provide {'temp':25} in the Message field.

  4. Provide any value as Device ID since it is only for testing purpose.

  5. Click Save.



The function will now be executed and the value {'temp':30} will be displayed as the output.

Info
Learn how to execute and test a message handler custom function that utilizes State Memory.

 

 


      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsRetailOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceForms for Solopreneurs
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit
                              Forms for Government
                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic FormsInsurance
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsWufoo alternativeEncrypted Forms
                              Accessible FormsTypeform alternativeSecure Forms

                              WCAG

                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now






                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media

                                                                  Use cases

                                                                  Make the most of Zoho Desk with the use cases.

                                                                   
                                                                    

                                                                  eBooks

                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                                   
                                                                    

                                                                  Videos

                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                                   
                                                                    

                                                                  Webinar

                                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                                   
                                                                    
                                                                  • Desk Community Learning Series


                                                                  • Meetups


                                                                  • Ask the Experts


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner



                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now










                                                                                                                            • Related Articles

                                                                                                                            • Creating a Message Handler

                                                                                                                              A message handler can be created in a Zoho IoT application by selecting "Message Handler" in the Category field while creating a custom function. Configuring the fields while creating a message handler Language: Deluge is the supported language for ...
                                                                                                                            • Testing State Memory Enabled Message Handler Custom Function

                                                                                                                              With state memory enabled, you can store values that can be used in successive messages to handle the incoming messages. We will go through a sample code to understand how state memory works while creating a custom function. headerMap = ...
                                                                                                                            • Specifications of message handler (deluge script)

                                                                                                                              A message handler custom function can be used to enrich the data sent by the connected device. The custom function is written using the deluge scripting language. In this document, we provide a sample code to demonstrate how a message handler ...
                                                                                                                            • Understanding message formatter and message handler

                                                                                                                              In the Zoho IoT application, data sent from the gateway/smart device can be enhanced further. This includes decoding raw payload into a usable JSON format and performing additional computations and enrich by calling external API's. This is achieved ...
                                                                                                                            • Adding a Message Handler through a Device Instance

                                                                                                                              A message handler custom function can be added through a device instance in the end application. To add a message handler through a device, Access the End Application. Select Devices > Devices in the left pane. Click on the name of the device for ...
                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources