12 Replies Latest reply on Jul 8, 2009 1:05 AM by kel45

    event gateway handling

    kel45 Level 1

      Hi i am using the main.cfc in the examples using the onIncomingMessage event

       

      i am gettnig back a variable

      <cfset message="#data.message#">

       

      <!--- where did it come from? --->
      <cfset orig="#CFEvent.originatorID#">
      <cfset retValue = structNew()>
      <cfset retValue.command = "submit">
      <cfset retValue.sourceAddress = arguments.CFEVENT.gatewayid>
      <cfset retValue.destAddress = arguments.CFEVENT.originatorid>
      <cfset retValue.shortMessage = "echo: " & message>

       

      retValue.shortMessage contains all the data and is then written to a text file like this

       

      "Information","Thread-15","06/30/09","21:07:17","IM_MENU","echo: id:869990453 sub:001 dlvrd:001 submit date:0906301507 done date:0906301507 stat:DELIVRD err:000 text:"

       

      what i need is to set 2 variables

       

      1. MessageId = this is the "id" in the echo

      2. MessageStatus = this is the "stat"

       

      i am not sure how to get to this info?

        • 1. Re: event gateway handling
          Dileep_NR Level 2

          Hi,

           

          could you please paste ur main.cfc

          • 2. Re: event gateway handling
            kel45 Level 1

            main.cfc below, instead of writing to a txt file i need to create 2 variables to insert into my database

             

             

            <cffunction name="onIncomingMessage" output="no">
            <cfargument name="CFEvent" type="struct" required="yes">

             

            <!--- Get the message --->
            <cfset data=cfevent.DATA>

            <cfset message="#data.message#">

             

            <!--- where did it come from? --->
            <cfset orig="#CFEvent.originatorID#">
            <cfset retValue = structNew()>
            <cfset retValue.command = "submit">
            <cfset retValue.sourceAddress = arguments.CFEVENT.gatewayid>
            <cfset retValue.destAddress = arguments.CFEVENT.originatorid>
            <cfset retValue.shortMessage = "echo: " & messageId>

             

            <cflog file="smsTest" text="#retValue.shortMessage#">

             

             

             

            </cffunction>

            • 3. Re: event gateway handling
              mack_ Level 3

              ReFindNoCase("id:() .*stat:() ", retValue.shortMessage, 1,

              true) will get you the position and length of the id and stat in the

              message (you can use Mid to extract them).

               

              Mack

              • 4. Re: event gateway handling
                Dileep_NR Level 2

                Hi,

                 

                try this

                 

                 

                 

                <cfset temp= listgetat(retValue.shortMessage,6)>
                <cfset temparray= listtoarray(temp," ")>
                <cfset MessageId  = listgetat(temparray[2],2,":")>
                <cfset MessageStatus  = listgetat(temparray[9],2,":")>

                • 5. Re: event gateway handling
                  kel45 Level 1

                  Hi i have tried the below, which did not work, i am not sure how i can debug this to find what the error is, as its a event?

                   

                  <cfcomponent>
                  <cffunction name="onIncomingMessage" output="no">
                  <cfargument name="CFEvent" type="struct" required="yes">

                  <!--- Get the message --->
                  <cfset data=cfevent.DATA>
                  <cfset message="#data.message#">

                  <!--- where did it come from? --->
                  <cfset orig="#CFEvent.originatorID#">
                  <cfset retValue = structNew()>
                  <cfset retValue.command = "submit">
                  <cfset retValue.sourceAddress = arguments.CFEVENT.gatewayid>
                  <cfset retValue.destAddress = arguments.CFEVENT.originatorid>
                  <cfset retValue.shortMessage = "echo: " & message>

                  <cfset temp= listgetat(retValue.shortMessage,6)>
                  <cfset temparray= listtoarray(temp," ")>
                  <cfset MessageId  = listgetat(temparray[2],2,":")>
                  <cfset MessageStatus  = listgetat(temparray[9],2,":")>


                  <cflog file="smsTestCraig2" text="#MessageStatus#">


                  </cffunction>

                  • 6. Re: event gateway handling
                    mack_ Level 3

                    Use cflog to save information about the request to a log file.

                     

                    Here's the same statement as above but this time correctly escaped in code tags:

                    ReFindNoCase("id:([0-9]+) .*stat:([a-z]+) ", retValue.shortMessage, 1, true)
                    

                     

                    Mack

                    • 7. Re: event gateway handling
                      kel45 Level 1

                      ok thanks i have added the following, but nothing is written to the log file

                       

                      <cflog file="smsTestCraig2" text="#ReFindNoCase("id:([0-9]+) .*stat:([a-z]+) ", retValue.shortMessage, 1, true)#">

                      • 8. Re: event gateway handling
                        mack_ Level 3

                        That's because the ReFindNoCase returns a structure and the text

                        attribute expects a string (or something that can be converted to a

                        string).

                         

                        Test the regular expression outside the cfc, in a simple test file to

                        make sure it's working properly and place the code inside the CFC

                        after that.

                         

                        Mack

                        • 9. Re: event gateway handling
                          Dileep_NR Level 2

                          try this

                           

                           

                          <cfset st1=ReFindNoCase("id:([0-9]+) .*stat:([a-z]+) ", retValue.shortMessage, 1, true)>

                          <cfloop index = "i" from = "2" to = "#ArrayLen(st1.pos)#">
                              <cfset testval  = testval & Mid(t,st1.pos[i],st1.len[i]) & "|">
                          </cfloop>

                           

                          <cflog file="smsTestCraig2" text="#testval #">

                          • 10. Re: event gateway handling
                            kel45 Level 1

                            ok i have tried the following in a test file, but i just get 2 empty strings?

                             


                            <cfset retValue.shortMessage = "echo: id:869990453 sub:001 dlvrd:001 submit date:0906301507 done date:0906301507 stat:DELIVRD err:000 text:">
                            <cfset testval = "">

                             

                            <cfset st1=ReFindNoCase("id:([0-9]+) .*stat:([a-z]+) ", retValue.shortMessage, 1, true)>

                             

                            <cfloop index = "i" from = "2" to = "#ArrayLen(st1.pos)#">
                                <cfset testval = testval & Mid(true, st1.pos[i],st1.len[i]) & "|">

                            </cfloop>

                             

                            <cfdump var="#testval#">

                            • 11. Re: event gateway handling
                              mack_ Level 3

                              The first parameter of the Mid function is not a boolean but the

                              string from which you want to extract the substring.

                               

                              Mack

                              • 12. Re: event gateway handling
                                kel45 Level 1

                                hi so what should the first value be?

                                i have tried st1?