<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <font face="monospace">Hi there,<br>
      <br>
      trying to maintain a dialog stateful UAS from script level may be
      something difficult and painful to do. Maybe you should take a
      look at the UAC/UAS support provided by the b2b_entities module in
      OpenSIPS 3.4:<br>
         
<a class="moz-txt-link-freetext" href="https://blog.opensips.org/2023/03/22/api-driven-sip-user-agent-end-point-with-opensips-3-4/">https://blog.opensips.org/2023/03/22/api-driven-sip-user-agent-end-point-with-opensips-3-4/</a><br>
      <br>
      Regards,<br>
    </font>
    <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu

OpenSIPS Founder and Developer
  <a class="moz-txt-link-freetext" href="https://www.opensips-solutions.com">https://www.opensips-solutions.com</a>
  <a class="moz-txt-link-freetext" href="https://www.siphub.com">https://www.siphub.com</a></pre>
    <div class="moz-cite-prefix">On 11/11/23 3:26 AM, Kevin Kennedy
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CABDXsRzy6sSC+xT6Ri95OwEABdTfN1166N1yfDJiCgz3_MP9UA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">I was able to send the BYE to the call by adding a
        parameter in the dialog module to timeout the dialog with a
        short time letting the announcement play, and added the
        create_dialog with the flag of B to send BYE on dialog timeout
        at the beginning of the route.  Now that the transactions are
        working correctly, I can use the same route for the calls with
        SDP as well and tighten up the script.  Thanks for helping out
        with some code examples, and letting me update on my progress on
        this thread.  Hopefully this can help someone else out having a
        similar problem when trying to use Opensips with RTPENGINE as an
        announcement server.
        <div><br>
        </div>
        <div>modparam("dialog", "default_timeout", 12)<br>
        </div>
        <div><br>
        </div>
        <div>route["RTPENGINE"]{<br>
              if (has_body("application/sdp")) {<br>
                  create_dialog("B");<br>
                  rtpengine_offer();<br>
                  $json(reply) := $rtpquery;<br>
                 
          $var(port)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
          port);<br>
                 
          $var(addr)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
          address);<br>
                  remove_body_part();<br>
                 
append_to_reply("Contact:<a class="moz-txt-link-rfc2396E" href="sip:$rU@$socket_in(ip):$socket_in(port)"><sip:$rU@$socket_in(ip):$socket_in(port)></a>\r\n");<br>
                  append_to_reply("Content-Type: application/sdp\r\n");
          <br>
                  $var(body) = $(rb{re.subst,/(IP4.).*/\1$var(addr)/g});
          <br>
                  $var(body) =
          $(var(body){re.subst,/(audio.)...../\1$var(port)/g});<br>
                  t_reply_with_body(200, "OK", $var(body));<br>
                  rtpengine_play_media("call-id=$ci from-tag=$ft
          file=/etc/rtpengine/unk_num.wav");<br>
                  exit;<br>
              } else {<br>
                  create_dialog("B");<br>
                  $var(newbody) = ("v=0\r\no=Opensips " + $Ts + " 0 IN
          IP4 " + $socket_in(ip) + "\r\ns=-\r\nc=IN IP4 " +
          $socket_in(ip) + "\r\nt=0 0\r\nm=audio " + $sp + " RTP/AVP 0
          101\r\na=sendrecv\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:101
          telephone-event/8000\r\na=fmtp:101 0-15\r\n");<br>
                  rtpengine_offer("from-tag=$ft
          replace-session-connection trust-address replace-origin
          codec-strip-g729",,$var(body),$var(newbody));<br>
                  $json(reply) := $rtpquery;<br>
                 
          $var(port)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
          port);<br>
                 
          $var(addr)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
          address);<br>
                 
append_to_reply("Contact:<<a class="moz-txt-link-freetext" href="sip:$rU@$socket_in(ip):$socket_in(port)\r\n">sip:$rU@$socket_in(ip):$socket_in(port)\r\n</a>");<br>
                  append_to_reply("Content-Type: application/sdp\r\n");<br>
                  $var(body) =
          $(var(body){re.subst,/(audio.)...../\1$var(port)/g});<br>
                  t_reply_with_body(200, "OK", $var(body));<br>
                  rtpengine_play_media("call-id=$ci from-tag=$ft
          file=/etc/rtpengine/unk_num.wav");<br>
                  exit;<br>
              }<br>
          <br>
          }<br>
        </div>
        <div><br>
        </div>
        <div>Thank you.</div>
        <div><br>
          Kevin</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, Nov 10, 2023 at
          4:54 PM Kevin Kennedy <<a
            href="mailto:kennedy4260@gmail.com" moz-do-not-send="true">kennedy4260@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">Looks like if I put t_newtran(); in the main
            route this created the transaction and allowed the ACK to be
            recognized.  Now How do I force Opensips to send a BYE.
            <div><br>
            </div>
            <div>Thank you.</div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Fri, Nov 10, 2023 at
              11:44 AM Kevin Kennedy <<a
                href="mailto:kennedy4260@gmail.com" target="_blank"
                moz-do-not-send="true">kennedy4260@gmail.com</a>>
              wrote:<br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">
              <div dir="ltr">
                <div dir="ltr"><br>
                </div>
                <br>
                <div class="gmail_quote">
                  <blockquote class="gmail_quote" style="margin:0px 0px
                    0px 0.8ex;border-left:1px solid
                    rgb(204,204,204);padding-left:1ex">
                    <div class="gmail_quote">
                      <blockquote class="gmail_quote" style="margin:0px
                        0px 0px 0.8ex;border-left:1px solid
                        rgb(204,204,204);padding-left:1ex">
                        <div class="gmail_quote">
                          <blockquote class="gmail_quote"
                            style="margin:0px 0px 0px
                            0.8ex;border-left:1px solid
                            rgb(204,204,204);padding-left:1ex">
                            <div class="gmail_quote">
                              <blockquote class="gmail_quote"
                                style="margin:0px 0px 0px
                                0.8ex;border-left:1px solid
                                rgb(204,204,204);padding-left:1ex">
                                <div class="gmail_quote">
                                  <blockquote class="gmail_quote"
                                    style="margin:0px 0px 0px
                                    0.8ex;border-left:1px solid
                                    rgb(204,204,204);padding-left:1ex">
                                    <div class="gmail_quote">
                                      <blockquote class="gmail_quote"
                                        style="margin:0px 0px 0px
                                        0.8ex;border-left:1px solid
                                        rgb(204,204,204);padding-left:1ex">
                                        <div class="gmail_quote">
                                          <blockquote
                                            class="gmail_quote"
                                            style="margin:0px 0px 0px
                                            0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex"><br>
                                            I was able to get audio, 
                                            The problem I was having is
                                            the Originator string in the
                                            SDP.  However, I am still
                                            having the same issue with
                                            accepting the ACK from the
                                            Originator and not resending
                                            the 200OK.  Can someone
                                            please help with this issue?
                                            <div><br>
                                            </div>
                                            <div>Thank you</div>
                                            <div><br>
                                              <div><b>Code snippet for
                                                  the Late Media route</b></div>
                                              <div>route["LateMedia3"]{<br>
                                                    if
                                                (has_body("application/sdp"))
                                                {<br>
                                                        xlog("########
                                                Entered route LateMedia3
                                                with Fake SDP from
                                                Originator
                                                ########\r\n");<span
                                                  style="color:rgb(80,0,80)"><br>
                                                         
                                                  rtpengine_offer();<br>
                                                          $json(reply)
                                                  := $rtpquery;<br>
                                                         
                                                  $var(port)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
                                                  port);<br>
                                                </span>       
                                                $var(addr)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
                                                address);<br>
                                                       
                                                remove_body_part();<br>
                                                       
append_to_reply("Contact:<a class="moz-txt-link-rfc2396E" href="sip:$rU@$socket_in(ip):$socket_in(port);user=phone"><sip:$rU@$socket_in(ip):$socket_in(port);user=phone></a>\r\n");<span
style="color:rgb(80,0,80)"><br>
                                                         
                                                  append_to_reply("Content-Type:
                                                  application/sdp\r\n");<br>
                                                </span>       
                                                $var(body) =
                                                $(rb{re.subst,/(IP4.).*/\1$var(addr)/g});<span
style="color:rgb(80,0,80)"><br>
                                                          $var(body) =
                                                  $(var(body){re.subst,/(audio.)...../\1$var(port)/g});<br>
                                                         
                                                  t_reply_with_body(200,
                                                  "OK", $var(body));<br>
                                                </span>       
                                                rtpengine_play_media("call-id=$ci
                                                from-tag=$ft
                                                file=/etc/rtpengine/unk_num.wav");<br>
                                                        async(sleep(10),
                                                after_media);<br>
                                                     } else {<br>
                                                        xlog("########
                                                Entered route LateMedia3
                                                No SDP received, Create
                                                one from variable
                                                ########\r\n");<br>
                                                        $var(newbody) =
                                                ("v=0\r\no=Opensips " +
                                                $Ts + " 0 IN IP4
                                                10.255.100.147\r\ns=-\r\nc=IN
                                                IP4
                                                10.255.100.147\r\nt=0
                                                0\r\nm=audio 3140
                                                RTP/AVP 0 101\r\na<br>
                                                =sendrecv\r\na=rtpmap:0
PCMU/8000\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\n");<br>
                                                       
                                                xlog("#########################
                                                Body to RTPENGINE is
                                                ###########################\r\n$var(newbody)\r\n");<span
style="color:rgb(80,0,80)"><br>
                                                         
                                                  rtpengine_offer("from-tag=$ft
replace-session-connection trust-address replace-origin
                                                  codec-strip-g729",,$var(body),$var(newbody));<br>
                                                </span>       
                                                xlog("#########################
                                                Body from RTPENGINE is
                                                ###########################\r\n$var(body)\r\n");<span
style="color:rgb(80,0,80)"><br>
                                                          $json(reply)
                                                  := $rtpquery;<br>
                                                         
                                                  $var(port)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
                                                  port);<br>
                                                </span>       
                                                $var(addr)=$json_pretty(reply/tags/$ft/medias[0]/streams[0]/local
                                                address);<br>
                                                       
append_to_reply("Contact:<a class="moz-txt-link-rfc2396E" href="sip:$rU@$socket_in(ip):$socket_in(port);transport=udp"><sip:$rU@$socket_in(ip):$socket_in(port);transport=udp></a>\r\n");<span
style="color:rgb(80,0,80)"><br>
                                                         
                                                  append_to_reply("Content-Type:
                                                  application/sdp\r\n");<br>
                                                </span>       
                                                $var(body) =
                                                $(var(body){re.subst,/(IP4.).*/\1$var(addr)/g});<span
style="color:rgb(80,0,80)"><br>
                                                          $var(body) =
                                                  $(var(body){re.subst,/(audio.)...../\1$var(port)/g});<br>
                                                </span>       
                                                xlog("#########################
                                                Body being sent in Reply
                                                is
                                                ######################\r\n$var(body)\r\n");<br>
                                                       
                                                t_reply_with_body(200,
                                                "OK", $var(body));<span
style="color:rgb(80,0,80)"><br>
                                                         
                                                  rtpengine_play_media("call-id=$ci
                                                  from-tag=$ft
                                                  file=/etc/rtpengine/unk_num.wav");<br>
                                                         
                                                  async(sleep(10),
                                                  after_media);<br>
                                                          }<br>
                                                  }<br>
                                                  <br>
                                                  route[after_media]<br>
                                                      { if
                                                  (t_was_cancelled()) {<br>
                                                         
                                                  rtpengine_delete();<br>
                                                          exit;<br>
                                                      } else {<br>
                                                         
                                                  rtpengine_delete();<br>
                                                         
                                                  sl_send_reply(486,"Busy
                                                  here");<br>
                                                          exit;<br>
                                                      }<br>
                                                  }</span></div>
                                            </div>
                                          </blockquote>
                                        </div>
                                      </blockquote>
                                    </div>
                                  </blockquote>
                                </div>
                              </blockquote>
                            </div>
                          </blockquote>
                        </div>
                      </blockquote>
                    </div>
                  </blockquote>
                </div>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>