在任务 Microsoft Teams 的 iframe 中发送 POST 请求
Sending POST request in iframe of task Microsoft Teams
目前,我有 Microsoft Teams 机器人,它有一个扩展按钮,可以在 iframe 中打开一个 HTML 页面。在 HTML 页面上,有一个带有提交按钮的表单,用于提交用户输入的信息。我 运行 遇到的问题是,当用户点击提交按钮时,它不会发出 HTTP POST 请求。我已经在团队之外测试了 iframe,它运行良好。我想知道这是否是我如何设置 iframe 或实际 HTML 页面设置或其他问题。谢谢!
这很可能与您的应用清单文件中的有效域列表有关。你在使用 App Studio 吗?如果是这样,在 "Domains and Permissions" 部分,您需要将 POST 端点列为有效域(只是域部分,而不是完整的 url)。
如果您不使用 App Studio,或者只是想获得更多参考,请参阅 here
您是在使用 microsoftTeams.tasks.submitTask()
函数,还是只是想直接执行 POST?我怀疑你在做后者。团队必须负责实际提交,否则它不知道 POST 曾经发生过,因为它发生在 <iframe>
.
中
如果这是您的问题,请参阅此处的操作示例。这是 Azure 示例 运行 中 the JS/Pug code 的摘录;我刚刚测试了它,它工作正常:
[...]
function validateForm() {
let customerInfo = {
name: document.forms["customerForm"]["name"].value,
email: document.forms["customerForm"]["email"].value,
favoriteBook: document.forms["customerForm"]["favoriteBook"].value
}
guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
let password = document.getElementById("pw").value;
if (guidRegex.test(password)) {
microsoftTeams.tasks.submitTask(customerInfo, password); // hidden feature to test bogus completion appId
}
else {
microsoftTeams.tasks.submitTask(customerInfo, "#{appId}"); //- appId is passed at render time in tabs.ts
}
return true;
}
[...]
div(class='surface')
div(class='panel')
div(class='font-semibold font-title') Enter new customer information:
form(method='POST' id="customerForm" action='/register' onSubmit="return validateForm()")
div
div.form-group(class="form-field-input" style="margin-bottom: 10px; margin-top: 10px")
label(for='name') Name:
input#name.form-control.input-field(type='text', placeholder='first and last' name='name' tabindex=1 autofocus)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='email') Email:
input#email.form-control.input-field(type='email', placeholder='name@email.com' name='email' tabindex=2)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='favoriteBook') Favorite book:
input#favoriteBook.form-control.input-field(type='text', placeholder='title of book' name='favoriteBook' tabindex=3)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='pw') Password:
input#pw.form-control.input-field(type='password' name='password' tabindex=4)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='pw2') Confirm password:
input#pw2.form-control.input-field(type='password' name='confirmPassword' style="margin-bottom: 10px;" tabindex=4)
button.btn.button-primary(type='submit' tabindex=5) Sign up
目前,我有 Microsoft Teams 机器人,它有一个扩展按钮,可以在 iframe 中打开一个 HTML 页面。在 HTML 页面上,有一个带有提交按钮的表单,用于提交用户输入的信息。我 运行 遇到的问题是,当用户点击提交按钮时,它不会发出 HTTP POST 请求。我已经在团队之外测试了 iframe,它运行良好。我想知道这是否是我如何设置 iframe 或实际 HTML 页面设置或其他问题。谢谢!
这很可能与您的应用清单文件中的有效域列表有关。你在使用 App Studio 吗?如果是这样,在 "Domains and Permissions" 部分,您需要将 POST 端点列为有效域(只是域部分,而不是完整的 url)。
如果您不使用 App Studio,或者只是想获得更多参考,请参阅 here
您是在使用 microsoftTeams.tasks.submitTask()
函数,还是只是想直接执行 POST?我怀疑你在做后者。团队必须负责实际提交,否则它不知道 POST 曾经发生过,因为它发生在 <iframe>
.
如果这是您的问题,请参阅此处的操作示例。这是 Azure 示例 运行 中 the JS/Pug code 的摘录;我刚刚测试了它,它工作正常:
[...]
function validateForm() {
let customerInfo = {
name: document.forms["customerForm"]["name"].value,
email: document.forms["customerForm"]["email"].value,
favoriteBook: document.forms["customerForm"]["favoriteBook"].value
}
guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
let password = document.getElementById("pw").value;
if (guidRegex.test(password)) {
microsoftTeams.tasks.submitTask(customerInfo, password); // hidden feature to test bogus completion appId
}
else {
microsoftTeams.tasks.submitTask(customerInfo, "#{appId}"); //- appId is passed at render time in tabs.ts
}
return true;
}
[...]
div(class='surface')
div(class='panel')
div(class='font-semibold font-title') Enter new customer information:
form(method='POST' id="customerForm" action='/register' onSubmit="return validateForm()")
div
div.form-group(class="form-field-input" style="margin-bottom: 10px; margin-top: 10px")
label(for='name') Name:
input#name.form-control.input-field(type='text', placeholder='first and last' name='name' tabindex=1 autofocus)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='email') Email:
input#email.form-control.input-field(type='email', placeholder='name@email.com' name='email' tabindex=2)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='favoriteBook') Favorite book:
input#favoriteBook.form-control.input-field(type='text', placeholder='title of book' name='favoriteBook' tabindex=3)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='pw') Password:
input#pw.form-control.input-field(type='password' name='password' tabindex=4)
div.form-group(class="form-field-input" style="margin-bottom: 10px;")
label(for='pw2') Confirm password:
input#pw2.form-control.input-field(type='password' name='confirmPassword' style="margin-bottom: 10px;" tabindex=4)
button.btn.button-primary(type='submit' tabindex=5) Sign up