Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5 Automations to Level-Up Your Blog with Directus #148

Open
4 tasks done
khabdrick opened this issue Apr 22, 2024 · 27 comments · May be fixed by #243
Open
4 tasks done

5 Automations to Level-Up Your Blog with Directus #148

khabdrick opened this issue Apr 22, 2024 · 27 comments · May be fixed by #243
Assignees
Labels

Comments

@khabdrick
Copy link

What is your idea?

The idea is to use Directus to fully automate a blogging platform on Directus. This approach aims to automate various aspects of managing a blog, from content creation and scheduling to interactions with readers and integration with third-party services.
Setting up a flow to publish snippet of blog posts in email newsletters and social media platform.
Configure a flow to alert blog authors or moderators of new comments that require attention.

What are the key takeaways from your post?

  • Practical application of working with Directus flow and triggers
  • Implement Email Newsletter notification
  • Automating social media sharing when a blog post is published.

What type of post is this?

Tips, Tricks, or Best Practice

Country of residence

Nigeria

Terms & Conditions

  • You understand that submitting this form does not mean we accept your proposal. We will accept proposals at our discretion.
  • You understand that to be paid you will need to generate an invoice to us once the final draft of your work is completed.
  • You understand that you will grant us an unlimited license to post and promote your work as part of this program. You may repost, but using our copy as the canonical source.
  • You are aged 18 or over.
Copy link

Thank you for submitting an idea for our guest blog.

We work through new ideas every few weeks as we put together our content schedule. This means you may not get an immediate response as to whether your idea has been accepted, or any follow-up questions we have to clarify your idea.

If your idea is accepted, we will provide a deadline for first draft and how much we can pay you for the post. You will have a few days to confirm whether you are still able and willing to write the post.

If you have any questions in the meantime, feel free to add a comment to this issue.

@phazonoverload
Copy link
Contributor

I like this as a post around setting up automations. You've provided some ideas - can you provide more a concrete list of what you would tackle in this post? Maybe 5?

@mvhammedali
Copy link

mvhammedali commented Apr 29, 2024

Okay @phazonoverload , here is what I will tackle:

  1. Automate content publishing workflow on approval.
  2. Automate the process of resizing images for the profile
  3. Setting up a Flow for Email Newsletter Notifications
  4. Automating content promotion on X (formerly Twitter)
  5. Configuring Alerts for New Comments

I am open to suggestions if there are any.

@phazonoverload
Copy link
Contributor

I like this post as a "5 Automations to Level-Up Your Blog with Directus".

How are these?

  • Automate content publishing workflow on approval.
  • Automating content promotion on X (formerly Twitter)
  • Configuring alerts for new comments
  • Automatic SEO summary writing (you can use the AI Writer marketplace extension for this)
  • Automated translation of new posts

As brief as possible for each one as I want the takeaway to be how easy it is.

Based on the agreed scope we can pay $500 for this post.

This post will be included as part of our July content schedule. The first draft is due on June 1 so we have time to properly review it and you have time to respond.

If interested and you’re happy to commit to the deadline, please let me know in the next few days and I will mark this issue as Approved.

The process is detailed in the README of this repo 😄

@phazonoverload phazonoverload changed the title How to Automate Your Blog Actions on Directus 5 Automations to Level-Up Your Blog with Directus May 7, 2024
@khabdrick
Copy link
Author

@phazonoverload every thing is good.
But what did you mean by automated translation of new posts?

@phazonoverload
Copy link
Contributor

New item created or updated -> run through a translation service, save it as a translation.

@phazonoverload
Copy link
Contributor

We have an ai translation operation you can use

@khabdrick
Copy link
Author

Ohh okay
But do you know if the ai module is available on the local version of Directus?

@phazonoverload
Copy link
Contributor

Yes, you can install it directly from the marketplace on Directus however it is hosted.

@khabdrick
Copy link
Author

Okay, I will need a day or two to get familiar with it first so I will know for sure that I will be able to work on it.
Sounds good?

@phazonoverload
Copy link
Contributor

Yes - i will leave this open until you say you're happy with how the idea has evolved, and we'll go from there

@mvhammedali
Copy link

Okay. I can work on it. I saw that It returns the translated string with no formatting.
Hope that will not be an issue?

@khabdrick
Copy link
Author

If everything is okay I can work on it with the current deadline.

@phazonoverload
Copy link
Contributor

Yes that's fine, all good.

@mvhammedali
Copy link

Hello there, I am struggling with something here, maybe you could give some insight. Based on the "Configuring alerts for new comments".
I created separate collection for article and comment, did one to many and many to one, respectively. In the trigger I am listening for when a comment is created, but in the payload I am getting the ID of the article the comment is attached to.
My question is, how can I get the title of the article from that ID in the payload 😢
Or is there any other way I can tackle this?

@phazonoverload
Copy link
Contributor

Hey! Tack on a read data collection and put in the ID returned from the previous step

@mvhammedali
Copy link

It works, thanks 🙇 .
It's actually more straightforward than it appeared before 😄

@mvhammedali
Copy link

Sorry I have to disturb you again.
I am done with all the other workflows except the Twitter one. I just realized there is a limitation to the run script operation, and I didn't see any option in the marketplace to help me with it.
This is the script:

const got = require('got');
const crypto = require('crypto');
const OAuth = require('oauth-1.0a');
const qs = require('querystring');

const consumer_key = "Aee0Y3pnwg6Ouuuuuuuuuuuuuuuuuu";
const consumer_secret = "muiThn0Y5s11wesGefmjFKvvvvvvvvvvvvvvvvvvvvvvvvvv";

const endpointURL = `https://api.twitter.com/2/tweets`;

const requestTokenURL = 'https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write';
const authorizeURL = new URL('https://api.twitter.com/oauth/authorize');
const accessTokenURL = 'https://api.twitter.com/oauth/access_token';

const oauth = OAuth({
  consumer: {
    key: consumer_key,
    secret: consumer_secret
  },
  signature_method: 'HMAC-SHA1',
  hash_function: (baseString, key) => crypto.createHmac('sha1', key).update(baseString).digest('base64')
});

async function requestToken() {
  const authHeader = oauth.toHeader(oauth.authorize({
    url: requestTokenURL,
    method: 'POST'
  }));

  const req = await got.post(requestTokenURL, {
    headers: {
      Authorization: authHeader["Authorization"]
    }
  });
  if (req.body) {
    return qs.parse(req.body);
  } else {
    throw new Error('Cannot get an OAuth request token');
  }
}

async function accessToken({ oauth_token, oauth_token_secret }, verifier) {
  const authHeader = oauth.toHeader(oauth.authorize({
    url: accessTokenURL,
    method: 'POST'
  }));
  const path = `https://api.twitter.com/oauth/access_token?oauth_verifier=${verifier}&oauth_token=${oauth_token}`
  const req = await got.post(path, {
    headers: {
      Authorization: authHeader["Authorization"]
    }
  });
  if (req.body) {
    return qs.parse(req.body);
  } else {
    throw new Error('Cannot get an OAuth request token');
  }
}

async function postTweet(token, text) {
  const data = {
    "text": text
  };

  const authHeader = oauth.toHeader(oauth.authorize({
    url: endpointURL,
    method: 'POST'
  }, token));

  const req = await got.post(endpointURL, {
    json: data,
    responseType: 'json',
    headers: {
      Authorization: authHeader["Authorization"],
      'user-agent': "v2CreateTweetJS",
      'content-type': "application/json",
      'accept': "application/json"
    }
  });
  if (req.body) {
    return req.body;
  } else {
    throw new Error('Unsuccessful request');
  }
}

module.exports = async function(data) {
  const x_post = data.$trigger.payload.x_post;
  if (!x_post) {
    return {};
  }

  try {
    const oAuthRequestToken = await requestToken();
    authorizeURL.searchParams.append('oauth_token', oAuthRequestToken.oauth_token);
    console.log('Please go here and authorize:', authorizeURL.href);
    
    const readline = require('readline').createInterface({
      input: process.stdin,
      output: process.stdout
    });
    
    const input = (prompt) => new Promise((resolve) => {
      readline.question(prompt, (out) => {
        readline.close();
        resolve(out);
      });
    });
    
    const pin = await input('Paste the PIN here: ');
    const oAuthAccessToken = await accessToken(oAuthRequestToken, pin.trim());
    const response = await postTweet(oAuthAccessToken, x_post);
    
    console.dir(response, { depth: null });
  } catch (e) {
    console.log(e);
    process.exit(-1);
  }
  process.exit();
};

And I am getting the following error, using import doesn't work too.

{
  "name": "ReferenceError",
  "message": "require is not defined"
}

@khabdrick
Copy link
Author

@phazonoverload
Copy link
Contributor

You can't use npm modules in run script - I can't review anything unless it's a PR on this repo, so I'm happy to start reviewing the post as it stands while you work out how to implement the final example.

@khabdrick
Copy link
Author

That's the problem, it's not possible to do it directly on directus.
I can't even use fetch alone to do it.

@phazonoverload
Copy link
Contributor

Hmm yes I see. Let's keep it simple then - maybe send it to Zapier which can then integrate to everything else?

@mvhammedali
Copy link

The X app is not available on Zapier, but I saw LinkedIn. I have tried implementing it with LinkedIn, and it is really not working on Directus when I try to reference data like {{item_read_cx40l.post}} or {{$trigger.payload.post}}.
I am out of ideas 😢

@phazonoverload
Copy link
Contributor

Just get it to zapier and that's enough

@mvhammedali
Copy link

It doesn't work like that, at least to my knowledge. There has to be an app to receive the data.

@phazonoverload
Copy link
Contributor

No there doesn't. You can set up a zap with a trigger and no steps as far as I know. Worst case scenario, use the log step. In the article just say you could hook it up to Twitter, LinkedIn, etc.

@mvhammedali
Copy link

It works now, thanks!!

@khabdrick khabdrick linked a pull request Jun 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants