code: def _aggregate_and_write_conversations(
      raw_intent_type,
      fetch_intent_type,
      datapath,
      domain,
      datatype,
      unannotated_id_map,
      skip_ids,
      start_file_idx=0,
  ):
      conversations_to_write = {}  # conversationId -> list of turns
      seen_conversations = set()
      out_dir = get_processed_multidogo_folder(
          datapath, domain, datatype, raw_intent_type
      )
      file_idx = start_file_idx
      intent_tsv = _get_annotated_tsv_data(
          datapath, domain, datatype, fetch_intent_type
      )
      next(intent_tsv)  # don't need the header in the first line
      print(f"Processing for {domain}, {fetch_intent_type}, {datatype}")
      for labeled_line in tqdm.tqdm(
          intent_tsv,
          total=_get_annotated_tsv_data_size(
              datapath, domain, datatype, fetch_intent_type
          )
          - 1,
      ):
          conversation_id = labeled_line[0]
          if conversation_id in skip_ids:
              continue
          if conversation_id not in seen_conversations:
              # new conversation, add text of conversation to conversations_to_write
              conversations_to_write[conversation_id] = {}
              found_raw_conversation = _add_utterances(
                  unannotated_id_map,
                  conversation_id,
                  conversations_to_write,
                  datapath,
                  domain,
              )
              seen_conversations.add(conversation_id)
              if not found_raw_conversation:
                  if DEBUG_MISSING_RAW_CONVERSATIONS:
                      print(
                          f"Could not find raw conversations for {conversation_id}"
                      )
                  skip_ids.add(conversation_id)
                  conversations_to_write.pop(conversation_id, None)
                  continue
          if fetch_intent_type == SENTENCE_INTENT:
              _get_sentence_labels_and_slots_map(
                  labeled_line, conversations_to_write
              )
          elif fetch_intent_type == TURN_INTENT:
              _get_turn_labels_and_slots_map(
                  labeled_line, conversations_to_write
              )
          else:
              raise KeyError(
                  "Invalid `fetch_intent_type`. This case should never be hit. Something is broken in the `build.py` file."
              )
      # Don't forget to dump out last file
      with open(f"{out_dir}/{file_idx}.json", "w+") as out_file:
          json.dump(conversations_to_write, out_file, indent=4)
          file_idx += 1
      # Return necessary outputs for next pass
      return file_idx, seen_conversations
  
imports: import parlai.core.build_data
  from parlai.core.build_data import DownloadableFile
  import csv
  from itertools import islice
  from pathlib import Path
  import os
  import json
  import re
  import tqdm
label_desc: Use image node_id 8 for calling a global function with example usage: _aggregate_and_write_conversations(raw_intent_type, fetch_intent_type, datapath, domain, datatype, unannotated_id_map, skip_ids, start_file_idx) and returns: file_idx,  seen_conversations