wrote getMessages function in main.js