To avoid code duplication, I would create a simple function taking a list of messages and the type of the messages, and then it would create the annotations for you by iterating over the list and setting the proper type.

(well, I know that anyway the code of the Web application is a mess and would need a lot of refactoring!)