Skip to content

Inbox Script Creation Steps

  • Figure out a query to which user you want sending the details/message. e.g here send details to all the user within in program
local ls = core.QueryUser(
    "given programs[af70e479-85ef-45f8-9c09-21065cc9cae5]"
)
  • Figure out an work flow details. Workflow here used to define a steps perform by user when sending a details. e.g

    local workflows = {
        ["regular-test"]="xxxxxx-xxxxxx-xxxxxx-workflow-id"
    }
    

  • For the better code readability made a code modular.It's mean used an function. e.g sending a inbox message to user make a code modular function like below.which accept user details and workflow details.

function invokeStuff(user, workflow)
    data = {
        title="test title", 
        summaryTitle="hello from subtitle",
        summary=showMessage(user.first..user.last),
        icon="fal fa-file-spreadsheet",
        userId=user.id    
    }

    core.InvokeInbox({
        recipient = user.id,
        id = workflow,
        data = data
    })
end

Example

Below is the example of script in which notify the user within in program to fill the details to every 90th day.

-- Lua Code
local ls = core.QueryUser(
    "given programs[xxxxxx-xxxxxx-xxxxxx-program-id]"
)

local workflows = {
    ["regular-test"]="xxxxxx-xxxxxx-xxxxxx-workflow-id"
}

function showMessage(name)
    return "こんにちは  "..name.." さん"
end

function invokeStuff(user, workflow)
    data = {
        title="test title", 
        summaryTitle="subtitle",
        summary=showMessage(user.first..user.last),
        icon="fal fa-file-spreadsheet",
        userId=user.id    
    }

    core.InvokeInbox({
        recipient = user.id,
        id = workflow,
        data = data
    })
end

for index, user in pairs(ls) do 
    local joinedDate = FormatDate(user.createdAt, "YYYY-MM-dd")
    local today = Now()
    local diffDays = DateDiff(joinedDate, today, "days")
    local shouldNotify = diffDays % 90
    if shouldNotify == 0 then
        local workflow = workflows["regular-test"]
        if workflow == nil then
            log.info("Not an available workflow")
        else   
            -- log the behavior for later troubleshooting
            log.info("user = " .. user.email .. 
                " Joined date = " .. joinedDate .. 
                " notify day = " .. today .. 
                " workflow = ".. workflow
            )  
            invokeStuff(user, workflow)
        end
    end 
end