← 返回
未分类 中文

MS Forms Auto

Automate Microsoft Forms daily submissions with M365 MFA support and dual-calendar integration to auto-fill training, content dev, and learning hours.
借助M365 MFA 支持和双日历集成,自动提交 Microsoft Forms 每日表单并自动填写培训、内容开发和学习时长。
claireaicodes claireaicodes 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 385
下载
💾 1
安装
1
版本
#automation#calendar#daily-log#latest#mfa#microsoft-forms#openclaw#playwright#productivity

概述

MS Forms Auto

Automate Microsoft Forms submission with Playwright, dual-calendar auto-fill, and M365 number-matching MFA support.

Quick Start

1. Install Dependencies

cd <skill-directory>
npm install
npx playwright install chromium

2. Set Up Credentials (one-time)

node scripts/setup-credentials.js

Creates config/credentials.json (gitignored) with M365 email/password.

3. First Login with MFA

xvfb-run --auto-servernum node scripts/mfa-login.js

When prompted, enter the 6-digit code from your Authenticator app. Saves auth state to config/storageState.json for headless reuse.

4. Fetch Calendar Data

node scripts/calendar-fetch.js              # Today (SGT)
node scripts/calendar-fetch.js --date 2026-03-18  # Specific date

Returns JSON with all form fields auto-populated from both calendars.

5. Submit the Form

node scripts/submit-daily.js

Reads today's entry from daily-entries/YYYY-MM-DD.json and submits.

Architecture

Dual Calendar System

CalendarURL SourcePurpose
------------------------------
Training (TMS)Built into scriptTraining Hours (source of truth)
OutlookBuilt into scriptContent Dev Hours, Other Items

Field Logic

#FieldSource
------------------
1DateToday (M/d/yyyy)
2Training HoursTraining calendar events
3Content Dev HoursOutlook calendar (content dev blockouts)
4Content Dev TopicEvent description from Outlook
5Learning Hoursmax(0, 8 - training - contentDev)
6Learning Topic2-3 random topics + any KT Sessions
7Other Items"Preparation, testing, and rehearsal for my next class" + Outlook events (excludes KT Sessions, training duplicates)
8Team HoursBlank
9Team DescriptionBlank

Fallback Defaults (if calendars fail)

FieldFallback
-----------------
Training Hours0
Content Dev Hours0
Content Dev TopicNA
Learning Hours8
Learning Topic3 random topics from pool
Other Items"Preparation, testing, and rehearsal for my next class"

Scripts

ScriptPurpose
-----------------
scripts/calendar-fetch.jsFetch both calendars, output all form fields
scripts/submit-with-mfa.jsPrimary: Combined MFA login + form submit in one session
scripts/submit-daily.jsSubmit form using saved storageState (no MFA)
scripts/mfa-login.jsStandalone MFA login (headed mode, saves state)
scripts/fill-form.jsCLI form filler with --date, --training, etc. args
scripts/setup-credentials.jsOne-time credential setup

Automated Pipeline (via OpenClaw Cron)

5:45 PM SGT → Pre-Fill cron (isolated) → calendar-fetch.js → draft entry JSON
6:00 PM SGT → Submit cron (main session) → asks Master for MFA code → 
              submit-with-mfa.js --code CODE → login + submit in one session → done

Why main session? The submit job runs in the main session so it can ask Master Phil for the 6-digit Authenticator code. Speed is critical — the MFA code expires in ~30 seconds, so the login and submit happen in a single browser session via submit-with-mfa.js.

Configuration Files

FilePurposeGitignored?
----------------------------
config/credentials.jsonM365 email + password
config/storageState.jsonSaved browser session (cookies)
config/calendars.jsonCalendar URLs (contains auth tokens)
config/calendars.json.exampleTemplate for calendar URLs
config/form-values.jsonLegacy form value defaults
daily-entries/Daily submission audit trail

MFA Handling (Improved)

This skill now intelligently handles both MFA and non-MFA scenarios:

Smart Behavior

  1. Auto-detection: The script attempts credential login first, then checks if MFA is required
  2. Flexible invocation:
    • node scripts/submit-with-mfa.js - Tries credentials only; if MFA appears, waits 30s for manual code entry or exits with code 2
    • node scripts/submit-with-mfa.js --code XXXXXX - Provides MFA code upfront; uses it if MFA appears, otherwise proceeds
  3. Graceful fallback: If credentials alone are sufficient (no MFA prompt), it works without requiring a code
  4. Exit codes:
    • 0 — Success
    • 1 — General error / invalid credentials
    • 2 — MFA required but no code provided (use --code flag)
    • 3 — MFA code wrong or expired
    • 4 — Form submission failed

Recommended Usage

For daily cron (6 PM SGT):

node scripts/submit-with-mfa.js --code [MFA_CODE_HERE]

This ensures speed (code ready) and handles both cases:

  • If MFA appears → code is used immediately
  • If no MFA → code is ignored, submission proceeds

For manual testing (unknown MFA requirement):

node scripts/submit-with-mfa.js

The script will wait 30 seconds on the MFA screen if needed, allowing you to manually type the code from your Authenticator app.

Why This Works

Microsoft's M365 authentication can be inconsistent:

  • Sometimes the OIDC cookie from previous login is still valid → no MFA needed
  • Sometimes the cookie expired → MFA required
  • Sometimes conditional access policies trigger MFA based on IP/device

The new logic eliminates the "always ask for MFA" problem by making the code optional and only using it when the MFA prompt actually appears.

Troubleshooting

  • Auth expired: Run xvfb-run --auto-servernum node scripts/mfa-login.js with a fresh Authenticator code
  • Calendar fetch fails: Script uses graceful fallbacks (0/NA defaults), form still submits
  • Form URL changed: Update the URL in scripts/submit-daily.js
  • Wrong field values: Run node scripts/calendar-fetch.js --date YYYY-MM-DD to verify calendar data
  • Detailed test plan: See references/TESTING_AUTH_WORKFLOW.md for comprehensive authentication workflow testing scenarios

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 07:58 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

knowledge-management

Knowledge Management

claireaicodes
按内容类型(研究、决策、洞察、经验、模式、项目、参考、教程等)将OpenClaw知识条目归类到本地文件夹中
★ 0 📥 2,101
office-efficiency

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 929 📥 187,024
office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 459 📥 152,982