DEV Community

Yota Hamada
Yota Hamada

Posted on

Automate ChatGPT with Workflow Engine built with Go (example of sending goal seek results by email)


This article shows how ChatGPT can be automated using Dagu, a free workflow engine. Specifically, we will show you how to use YAML definitions to run ChatGPT's API and automatically email the results.

What is a DAG workflow engine?

A workflow engine is, simply put, a tool for automatically executing the tasks you do on your computer. It does not simply execute tasks in simple sequence, but can also specify dependencies between tasks and execute tasks in parallel at the same time. The following graph is a DAG (Directed acyclic graph).


What is Dagu?

Dagu is a free, open source DAG workflow engine.


  • DAGs can be created with no code (no programming required).
  • All operations, including creating and running DAGs, can be done from a browser.
  • Just install the command on your Mac and use it.

Example of calling ChatGPT API and sending an answer by email

The following is an example of calling ChatGPT's API and sending the results by email.

Example workflow

What each step does is simple.

  1. call the ChatGPT API with the specified question
  2. extract the answers from the API response
  3. convert the response into an HTML email ready to be sent
  4. send the email.

As a result, you will receive an email that looks like this


Steps to use ChatGPT to automate goal seek questions

In this section, the Goal Seek prompt is used to automate Goal Seek. Note that any prompt can be automated in the same way by rewriting the contents of the DAG.

The prompt used:

[Goal] Goal to achieve.
a[i,1-5]=5 ideas to achieve a[i,0].
a[i+1,0]=a[i,1-5], which is the best idea to achieve a[i+1,0]=a[i,1-5]

Use this to calculate up to i=0-5 and put the results in an HTML table with 5 rows and 5 columns, 25 cells in total.

Installing Dagu

  1. Dagu can be installed using Homebrew.

    brew install yohamta/tap/dagu
  2. You can check if the installation is successful with the following command:

    dagu version

Launching Dagu Server

  1. Dagu server can be launched by the following command.

    dagu server
  2. Access http://localhost:8080 in your browser. You should see a screen similar to the following.

Creating a ChatGPT workflow.

  1. click on the three-line menu on the left. The following is what you will see in my environment. list
  2. press the 'NEW' button in the top right-hand corner and enter the name of the new DAG chatgpt_goalseek_example.
  3. press the 'EDIT' button in the bottom right-hand corner. Edit
  4. paste the following into the edit screen and save it ('SAVE' button).

    params: GOAL="Unique and interesting bullet-hell game."
      - OPENAI_API_KEY="ChatGPT API Key"
      - MY_EMAIL="Recipient email address"
      - FORMAT: >-
          Five ideas to achieve a[i,1-5]=a[i,0]. \n
          The best idea to achieve a[i+1,0]=a[i,1-5]. \n
          Use this to calculate up to i=0-5 and put the results into a HTML table with 5 rows and 5 columns, 25 squares in total. \n
      host: ""
      port: "587"
      username: "Mailgun username"
      password: "Mailgun password"
      - name: ask chatgpt
          type: http
            timeout: 1200
              Authorization: "Bearer $OPENAI_API_KEY"
              Content-Type: "application/json"
            silent: true
            body: |
              { "model": "gpt-3.5-turbo", "messages": [
                  {"role": "system", "content": "Act as a state-of-art chat AI. Please output the result in a table format with 5 rows and 5 columns. Format your reply in HTML code styled with beautiful CSS."},
                  {"role": "user", "content": "[Goal]${GOAL}\n${FORMAT}"}
        command: POST
        output: API_RESPONSE
      - name: get result
          type: jq
            raw: true
        command: ".choices[0].message.content"
        script: "$API_RESPONSE"
        output: MESSAGE_CONTENT
          - ask chatgpt
      - name: convert escaped unicode to plain HTML
        command: "sh"
        script: |
          unescaped=$(echo -e "$input" | sed 's/\\u003c/</g' | sed 's/\\u003e/>/g')
          echo "$unescaped"
        output: MESSAGE_CONTENT
          - get result
      - name: send mail
          type: mail
            to: "$MY_EMAIL"
            from: "$MY_EMAIL"
            subject: "goal seek result"
            message: "$MESSAGE_CONTENT"
          - convert escaped unicode to plain HTML

Setting up the ChatGPT API key and email sending server

  1. set up the ChatGPT API key
    Rewrite the ChatGPT API Key below with your ChatGPT API key.

      - OPENAI_API_KEY="ChatGPT API Key"
  2. set up a mail sending server
    Register with Mailgun and you can send emails for free. Rewrite the following Mailgun username and Mailgun password with your Mailgun username and password. You can also use other email services.

      host: ""
      port: "587"
      username: "Mailgun Username"
      password: "Mailgun Password"
  3. set the recipient email address
    Replace the following Recipient email address with the email address to which you want to send the ChatGPT response.

      - MY_EMAIL="Recipient email address".

Try it out and run it.

Press the 'START' button in the top right-hand corner to run the DAG. In the text box, put in what you want to ask for in the Goal Seek prompt. For example, put in The best and most interesting roguelike game idea.

The execution status is displayed in the browser.


If an error occurs, press the 'RETRY' button in the top right-hand corner; the error may occur if ChatGPT's API is heavy.

If successful, you will see the following screen.

You will then receive the following email. Oh no.
Image description


As you can see, the workflow engine allows you to automate ChatGPT API calls with no-code.

If you always run similar prompts, it may be useful to define a DAG.

You can do more interesting things by combining multiple inputs and outputs of ChatGPT's API. For example, ChatGPT responses could be passed to further APIs to improve or transform the results, and if defined as a DAG, it could be useful to combine multiple roles of ChatGPT, as the APIs can be called in parallel.

I can only dream of the things we could do with it!

Dagu is open source software that I am developing using the Go language.
I would be happy if you could participate in its development.

Top comments (0)