Hi,
The sort answer is: the "processing" code goes into the Run function of the process script.
As it was mentioned in a previous post answer, the place to look for information on how to write your own processes is:
https://neuroimage.usc.edu/brainstorm/Tutorials/TutUserProcess
While the process_average.m gives a similar result to your goal, to handle the many options in the process, there are extra functions besides the Run function. I'd suggest you to look at the simpler process file, process_example_customavg.m, for inspiration. This script is provided in the Examples section.
Best,
Raymundo