简体   繁体   中英

How to use velocity for SMS templates

I am working on a Java service that needs to send SMS through Amazon SNS.

I am using Velocity templates to generate personalized emails, and thought about using it for SMS as well.

But I don't think it is the right approach because the AWS SDK method for sending an SMS takes the message as a string. This would force me to generate a file and then read it to get the contents as a string.

The only alternative I can think of is storing the template as TINYTEXT (SMS size limit is 140 bytes) in the database, and use String.replaceAll() instead of velocity.

But I wanted to know if there is a better way to do it or if using velocity would hurt performance that much.

You can use velocity without generating a file until VelocityEngine.evaluate

renders the input string using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.

Example :

 VelocityContext context = new VelocityContext(); context.put("param", paramMap); context.put("placeList", placeList); StringWriter writer = new StringWriter(); ve.evaluate(context, writer, "", template); return writer.toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM