Strategies for sending weekly newsletter emails from Rails - ruby-on-rails

So we have about 50,000 users who have signed up for a weekly newsletter. The contents of this email is personalized for each user though, it's not a mass email.
We are using Rails 4 and Mandrill.
Right now we're taking about 12 hours every time we want to fire off this emails.rake task and I'm looking for a way to distribute that time or make it shorter.
What are some techniques I can use to improve this time that is only growing longer the more people sign up?
I was thinking of using mandrill templates, and just sending the json object to mandrill and have them send the email from their end, but I'm not really sure if this is even going to help improve speeds.
At the 50,000+ level: How do I keep email sending times manageable?

Looks like you could use MailyHerald. It is a Rails gem for managing application emails. It sends personalized emails in the background using Sidekiq worker threads which should help you out in terms of performance.
MailyHerald has a nice Web UI and works with email services like Amazon SES or Mandrill.

You need to probably look into Merge Tags on Mandrill. It allows you to define custom content per email. So you can break your newsletter sending into fewer API calls to Mandrill instead of 1 per email. The number of calls will just depend on the size of your data since I am sure there is probably a limit.
You can just create a template and put in merge vars such as *|custom_content_placeholder|** wherever you need user specific content to be placed. You can do this templating in your system and just pass it into the message or you can set it up in Mandrill and make a call to that template.
When you make the Mandrill API call to send an email or email template you just attach the JSON data such as:
"message": {
"global_merge_vars": [
{
"name": "global_placeholder",
"content": "Content to replace for all emails"
}
],
"merge_vars": [
{
"rcpt": "user#domain.com",
"vars": [
{
"name": "custom_content_placeholder",
"content": "User specific content"
},
{
"name": "custom_content_placeholder2",
"content": "More user specific content"
}
]
},
{
"rcpt": "user2#domain.com",
"vars": [
{
"name": "custom_content_placeholder",
"content": "User2 specific content"
},
{
"name": "custom_content_placeholder2",
"content": "More user2 specific content"
}
]
}
],
You can find more info on Merge Tags here:
https://mandrill.zendesk.com/hc/en-us/articles/205582487-How-to-Use-Merge-Tags-to-Add-Dynamic-Content
If you are familiar with handlebars for templating, Mandrill now supports it with the merge tags:
http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html

Related

Unfurl links blocks template

I'm using the link_shared events to unfurl links in my workspace, trying to generate a template that is as close to Slack's unfurling template as possible, but I have several issues -
Blocks have very large spacing between them, causing my 3 blocks to take a lot of space
I'm unable to have an image inlined with the text for the title, unless I'm using context, but this is causing the text to be very small.
Taking Slack's example of how link unfurling should look like and trying to mimic it with blocks should explain the differences. This is the blocks message, and here you can see the result as an image
So my main question is - does Slack use some internal blocks formatting not available in the API, or is it possible to achieve the same result?
Thanks a lot!
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":pager: *Slack*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<https://slack.com/features|Features>*"
}
},
{
"type": "image",
"title": {
"type": "plain_text",
"text": "Slack is where work flows. It's where the people you need, the information you share, and the tool you use come together to get things done.",
"emoji": true
},
"image_url": "https://a.slack-edge.com/13f94ee/marketing/img/homepage/self-serve-campaign/unfurl/img-unfurl-ss-campaign.jpg",
"alt_text": "Slack"
}
]
}
That example is not using the Slack block unfurl - it's an example of how a generic link would be displayed using the page's meta tags to display some additional information, using the favicon image.
If you wanted to create something similar you could use use a markdown block and an image block (like this) - but the file size would be displayed on a new line rather than after the text.
It took a bit of playing around, but I realized Slack is actually using message attachments (the legacy version of message formatting) in order to generate their link unfurls.
For example, if you want to unfurl a GitHub repository link, this is the payload you should send, and it'll generate an almost identical unfurling to what Slack is generating (a small Added by {app-name} will be added to the footer) -
unfurls["https://github.com/slackapi/bolt-js/"] = {
author_name: "GitHub",
author_icon: "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
title: "GitHub - slackapi/bolt-js: A framework to build Slack apps using JavaScript",
title_link: "https://github.com/slackapi/bolt-js/",
text: "A framework to build Slack apps using JavaScript. Contribute to slackapi/bolt-js development by creating an account on GitHub.",
image_url: "https://opengraph.githubassets.com/3e06f7eee96f05a53cd4905af3b296dfe333be7a902bb3e6a095770e87fd17fe/slackapi/bolt-js"
}

Twilio Taskrouter - How to add information to custom tasks?

I'm working with Twilio programmable video and I'd like to integrate it with TaskRouter.
Currently I can create custom tasks with a POST request to:
https://taskrouter.twilio.com/v1/Workspaces/{WorkspaceSID}/Tasks/
Yet regardless of what I put into the request body, the task shows up as "Anonymous Task, Reserved".
Is this an issue of formatting? I'd ideally like it to say something along the lines of "Incoming video request" with the customer name in the task-bar similar to how chat tasks look.
Here's the dummy data I tried passing in to no avail. I've tried a few different ways:
{
"attributes": {
"type": "video",
"contact": "+17777777777",
"customer-value": "gold",
"task-reason": "support",
"callSid": "CA42ed11...",
"name": "Joe",
"customer_name": "Joe"
}
"name": "Joe",
"customer_name": "Joe"
}
None of this data is passed through to the task. Any help would be appreciated.

Microsoft Graph: insert a message (mail) to user inbox

I have a Microsoft application (with Mail.Read/Write permissions) and I need to insert a mail (.eml extension file) to a user inbox.
Is that possible? I know that with Gsuite that can be done using the 'insert' API and was wondering if something similar exist with Graph API.
I'm not talking about sending new mail to the user or about inserting an attachment to existing message in the user inbox, but to insert completely new email to his inbox (without having to go through SPF or whatever checks that take place before mails usually get into end users inboxes).
Looking into Mail section under Graph API documentation wasn't so helpful.
If that not possible, perhaps there is a workaround?
EDIT: seems like the best option is to use "send mail" API and specify "saveToSentItems": False.. the only issue here as that my application will need to request the Mail.Send permission as well..
Thanks
You don't need to use the send mail api as all your doing is creating an Item in the Mailbox. If you want it to appear as a Sent Mail (rather then a draft) you do need to set the PidTagMessageFlags extended property (the same as you would in EWS https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-import-items-by-using-ews-in-exchange). Also if you want it to appear if its been sent in the past there are few additional extended properties you need to set. eg
{
"Subject": "test1234",
"Sender": {
"EmailAddress": {
"Name": "blah",
"Address": "blah#blah.com"
}
},
"Body": {
"ContentType": "HTML",
"Content": "123Body"
},
"SingleValueExtendedProperties": [
{
"PropertyId": "Integer 0x0E07",
"Value": "1"
},
{
"PropertyId": "SystemTime 0x0039",
"Value": "2019-06-12T10:10:47.2048+10:00"
},
{
"PropertyId": "SystemTime 0x0E06",
"Value": "2019-06-12T10:10:47.2048+10:00"
}
]
}

How do I connect my database to API.AI?

How do I connect my database to API.AI
Making every sentence into INTENT and creating entities for each doesn't seem to be a good idea? So what is the best possible way to go about?
As far as I know it is not possible yet, but you can switch to row mode and past your entities inCVS or JSON format OR import a JSON/CSV file containing all your entities.
The file should look like below (JSON format):
[
{
"value": "val1",
"synonyms": [
"syn1",
"syn2"
]
},
{
"value": "val2",
"synonyms": [
"syn21",
"syn22"
]
},
]
So you can image of writing a small job that reads entities from you DB and make a JSON/CSV file according the wanted format.
Once the job done, this process may dramatically facilitate the creation of your entities on api.ai.
If you use a webhook for an intent, you can pass params to your endpoint where you can do all the queries to your db
I did a demo where I was querying news (cheating as I was getting it from the web, but I could plug a DB).
The was getting requests such as:
"What are the latest news about France"
latest and France would be params that I send through to the webhook endpoint.
You would get the following JSON sent your endpoint by API.AI
"result": {
"source": "agent",
"resolvedQuery": "latest news about France",
"action": "show.news",
"actionIncomplete": false,
"parameters": {
"adjective": "latest",
"subject": "France"
}
Then you can query all the news for France and order them by latest
In my understanding the idea is to create entities that are "placeholders" for the values you need to query.
Then you teach the AI with few examples by tagging in the request what did the person ask. Let say someone asks:
"what is the oldest news about France?"
The AI may not know what is oldest thus you tell it is is an adjective and from now on you can get oldest as a param

mandrill web-hooks open event "list of opens"

We are using mandrill, and we have webhooks configured to track open events.
But I am a bit confused about the JSON format what mandrill provides.
In of the formats, for open event, we have a key called "opens"
"opens": [
{
"ts": 1420010190,
"ip": "0.0.0.0",
"location": null,
"ua": "Linux/Linux/Gmail image proxy/Gmail image proxy"
},
{
"ts": 1420020155,
"ip": "0.0.0.0",
"location": null,
"ua": "Linux/Linux/Gmail image proxy/Gmail image proxy"
},
],
Are these objects unique ?
will they be duplicates? if so, do mandrill adds all the open list for every event we receive?
From the docs what i could understand is mandrill sends a webhook for every open, if it is, what are these list of opens in every event. which one would i consider.
It will be really helpfull, if someone explain the format.
Thanks in advance.
If you only want to record the individual opens, just use the data at the top level of the webhook event (ts, event, location, ip, for example). Everything under the msg key is data about the message that Mandrill knows when the webhook is created (so it's in addition to information about the individual open that triggered the webhook event). So the msg.opens key will be a list of all opens Mandrill knows about for the message at that time.

Resources