get_conversation_history

in src/zgoog_conversation_agent/zgoog_cl_conversation_agent.clas.abap [0:0]


  METHOD get_conversation_history.

    DATA:
      lv_content_xstring TYPE xstring,
      lv_content_string  TYPE string,
      lt_bin_data        TYPE STANDARD TABLE OF char1024,
      lv_file_length     TYPE i.

    FIELD-SYMBOLS:
                   <ls_conversation_hist>  TYPE zgoog_conv_hist.

    SELECT *
      FROM zgoog_conv_hist
      INTO TABLE gt_conversation_hist
      WHERE session_id = gv_session_id.
    IF sy-subrc = 0.
      SORT gt_conversation_hist BY start_time DESCENDING.

    ENDIF.

    READ TABLE gt_conversation_hist ASSIGNING <ls_conversation_hist> INDEX 1.
    IF sy-subrc = 0.
      lv_content_xstring = cl_http_utility=>decode_x_base64( <ls_conversation_hist>-content ).

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = lv_content_xstring
        IMPORTING
          output_length = lv_file_length
        TABLES
          binary_tab    = lt_bin_data.

      CALL FUNCTION 'SCMS_BINARY_TO_STRING'
        EXPORTING
          input_length = lv_file_length
        IMPORTING
          text_buffer  = lv_content_string
        TABLES
          binary_tab   = lt_bin_data.

      /goog/cl_json_util=>deserialize_json( EXPORTING iv_json          = lv_content_string
                                                      iv_pretty_name   = /ui2/cl_json=>pretty_mode-extended
                                            IMPORTING es_data          = et_conversation_history ).

    ENDIF.