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

Setup Mailchimp feed from 'updates' page (or for new entries on this page) #1

Open
daaronr opened this issue Apr 22, 2023 · 5 comments

Comments

@daaronr
Copy link
Collaborator

daaronr commented Apr 22, 2023

This is the updates page
... but I'm also happy to do this with updates as 'new subpages' if that works better

Asked Gitbook:

I integrated MailChimp. I want to have a mailing list but all I want it to do is link/update when a particular page on my gitbook is updated (alternatively, when a new gitbook page is added within a particular folder).

Is this doable? Ideally the Mailchimp message would also paste in or embed the new content.

@daaronr
Copy link
Collaborator Author

daaronr commented Apr 22, 2023

Asked GPT4:

How can I get MailChimp to send an update to all subscribers whenever a particular page of a Gitbook is updated?

To automatically send an update to all subscribers whenever a particular page of a Gitbook is updated, you can follow these steps:

Response

  1. Set up a webhook in your Git repository:
    First, you need to set up a webhook in your Git repository (GitHub, GitLab, or Bitbucket) that triggers whenever a push event happens, including updates to a particular page.
  1. Create a simple web service to listen to the webhook:
    Next, you'll need to create a simple web service that listens to the webhook events. You can use a serverless function like AWS Lambda, Google Cloud Functions, or Vercel to create this service. The service should parse the payload received from the webhook, check if the updated page matches the specific page you want to monitor, and then proceed to send an email through Mailchimp if it does.
  1. Use Mailchimp API to send an email to all subscribers:
    When your web service receives a webhook event corresponding to the page update, it should use the Mailchimp API to send an email to all subscribers. To do this, you'll need to:

a. Register for a Mailchimp API key if you haven't already. Check the Mailchimp API documentation to learn how to create an API key.
b. Use the Mailchimp API to fetch your audience list. You can use the "Lists" endpoint to get the list ID of your audience.
c. Create a new email campaign using the "Campaigns" endpoint with the desired subject, from address, and content.
d. Send the email campaign to your subscribers using the "Send" action of the "Campaigns" endpoint.

Here's a simple example using Python, Flask, and the mailchimp_marketing library:


from flask import Flask, request, jsonify
import mailchimp_marketing
from mailchimp_marketing.api_client import ApiClientError

app = Flask(__name__)

MAILCHIMP_API_KEY = "your_mailchimp_api_key"
MAILCHIMP_LIST_ID = "your_mailchimp_list_id"
PAGE_TO_MONITOR = "your_page_to_monitor"

client = mailchimp_marketing.Client()
client.set_config({"api_key": MAILCHIMP_API_KEY, "server": "your_mailchimp_server_prefix"})

def send_mailchimp_email(subject, content):
    try:
        campaign = {
            "type": "regular",
            "recipients": {"list_id": MAILCHIMP_LIST_ID},
            "settings": {
                "subject_line": subject,
                "from_name": "Your Name",
                "reply_to": "[email protected]",
            },
        }
        response = client.campaigns.create(campaign)
        campaign_id = response["id"]

        content_update = {"html": content}
        client.campaigns.set_content(campaign_id, content_update)

        client.campaigns.send(campaign_id)
        print("Email sent successfully.")
    except ApiClientError as error:
        print("Error sending email: {}".format(error.text))

@app.route("/webhook", methods=["POST"])
def webhook():
    payload = request.json
    updated_files = []  # Extract the updated files from the webhook payload (depends on your Git provider)
    
    for file in updated_files:
        if PAGE_TO_MONITOR in file:
            subject = "Page Updated: {}".format(PAGE_TO_MONITOR)
            content = "The page {} has been updated. Check it out here: <a href='{}'>Link to the page</a>".format(PAGE_TO_MONITOR, "your_page_url")
            send_mailchimp_email(subject, content)
            break

    return jsonify({"status": "success"})

if __name__ == "__main__":
    app.run()

Remember to replace the placeholders with your actual

@daaronr
Copy link
Collaborator Author

daaronr commented Jun 1, 2023

#3 @fernandosmither This is the 'issue' (also in the projects board).
I think it's nearly done, thanks; as you say, I need to check it and tailor it.

@daaronr
Copy link
Collaborator Author

daaronr commented Jun 1, 2023

@fernandosmither Here's my documentation Is it correct?

@daaronr
Copy link
Collaborator Author

daaronr commented Jun 1, 2023

@fernandosmither

To check whether the emails were sent successfully, you can check (Github) for the status before the commit, which is a green check mark when sent, a yellow dot while it's on it, and a red cross if it failed

I'm confused: I thought it sends the emails when you commit. So how do I check 'before' I commit?

@fernandosmither
Copy link
Member

@fernandosmither

To check whether the emails were sent successfully, you can check (Github) for the status before the commit, which is a green check mark when sent, a yellow dot while it's on it, and a red cross if it failed

I'm confused: I thought it sends the emails when you commit. So how do I check 'before' I commit?

Sorry, I meant the status symbol before the commit in a spatial sense, not time. The commit hash is shown to the right of the status.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants