Showing posts with label EXM. Show all posts
Showing posts with label EXM. Show all posts

Thursday, November 15, 2018

Sending SMS messages with Sitecore EXM

I attended Pete Navarra's inspiring "EXM Live!" breakaway session at the Sitecore Symposium. An audience member asked whether it was possible to send SMS messages through EXM. Pete gave an answer, but I had a super short chat with him after, telling our approach to this.
I promised another audience member who overheard to post an overview of our solution here - I'm sorry I haven't gotten to it until now!

This was made a while ago, meaning it's for Sitecore 8.2 and EXM 3.4 (update 2)

Creating a message type


First I needed to create a new message type. Since an SMS can only send text, I used Sitecore's TextMail as a base. First step is to make a new template in Sitecore, which has Sitecore's Plain Text Message as base template.
Having this template, I went ahead and created a message type in my project, including all the usual suspects. The "IsCorrectMessageItem" implementation uses the ID of my new template to identify the version.

public class SMS : TextMail
{
 private readonly TextMailSource _curSource;

 protected SMS(Item item) : base(item)
 {
  this._curSource = (base.Source as TextMailSource);
 }

 public new static bool IsCorrectMessageItem(Item item)
 {
  return ItemUtilExt.IsTemplateDescendant(item, "{185B8860-3DFE-4B9E-A5DD-04A2D7DF3EC2}");
 }

 public static SMS FromItemEx(Item item)
 {
  if (!SMS.IsCorrectMessageItem(item))
  {
   return null;
  }
  return new SMS(item);
 }

 public override string GetMessageBody(bool preview)
 {
  return _curSource.Body;
 }

 public override object Clone()
 {
  SMS sms = new SMS(base.InnerItem);
  CloneFields(sms);
  return sms;
 }
}