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;
 }
}

Friday, November 9, 2018

Publish viewer/canceller using Sitecore Powershell Extensions

I have only just recently jumped the Sitecore Powershell Extensions (SPE) bandwagon, but I absolutely love it.
Most of the tasks I've used it for so far has been either very straight forward, or very client specific. However we were just asked by a client to make a publish viewer which would list details of current publish actions and queue, as well as being able to canceling queued items.
Similar applications has existed in the past, but it didn't seem like any of them worked properly on Sitecore 8.2 and 9.0 - SPE to the rescue!

First a couple of functions

Most of this could exist in one long script, I just really like splitting them up into individual scripts for easier reuse.

Get-PublishJobs

First off I made a function to get all jobs from the jobmanager, filter them to only see the PublishManager jobs, and then sorting them by PublishDate. This gives returns me a PowerShell array of relevant jobs.

function Get-PublishJobs() 
{
  $category = 'PublishManager'
  [Sitecore.Jobs.JobManager]::GetJobs() | 
           Where-Object -FilterScript { $_.Category -eq $category } | 
           sort @{expression={$_.Options.Parameters[0].PublishDate};Descending=$false}
}