@Anne Birgitte Sivesind Strebel
This forum shows an code example, you could check if it could help you count the message in Teams.
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.