Fix bugs with messaging

- fix 500 for non-numeric num_attachments
- fix 500 for num_attachments out of range
- fix 500 for non-existent message id
- [finishes #24603725]