python - BotFramework v4 主动消息仅适用于某些
问题描述
我的团队在 python 中使用 botframework 开发的机器人有一个奇怪的行为。我将开始说明一般行为:
- 每天,机器人都会通过自适应卡提出两个问题并给出答案(单个或多个)。
- 用户可以回答是否感兴趣
- 第二天,机器人将前一天问题的答案发送给回答问题的用户,然后再向所有订阅该频道的人发送两个问题。(这是通过主动消息完成的)。
问题来了:我保存了一个包含 id_user:conversation_reference 的字典,并在需要联系用户时检索它。前一天问题答案的消息部分到达所有回答正确的用户,而当天问题的消息部分只到达少数人。收到当天问题的人可能回答了前一天的问题,也可能没有回答。有这样的情况,用户每天都在回答,但没有收到新问题的通知,但是有一个命令来检索它们。我附上前一天答案的代码。
async def _send_proactive_message(id_context, key, result, conv_dict):
file_name = utils._filename_from_context(id_context[key])
_, _, question, _, _, _, correct_answer, expl, img1, img2=
utils.get_question(key, file_name)
expl_str = str(expl)
if(expl_str == 'None'):
expl_str = 'Nothing'
correct_answer_str = str(correct_answer)
for conversation_reference in conv_dict.values():
if(conversation_reference.user.id in result.keys()):
if (set(result[conversation_reference.user.id].split(',')) ==
set(correct_answer_str.split(';'))):
AppCredentials.trust_service_url(conversation_reference.service_url)
await ADAPTER.continue_conversation(
conversation_reference,
lambda turn_context: turn_context.send_activities([
Activity(
text="bla bla bla",
type=ActivityTypes.message,
attachments=[CardFactory.adaptive_card(cards[0])]
)
]),
APP_ID,
)
现在是当天问题的代码,以前的格式是一样的,但我还是遇到了上面列出的问题。
async def _send_question_of_the_day(conv_dict):
cards = await utils._create_adaptive_card_attachment()
now = datetime.now()
data = now.strftime('%d/%m/%Y')
for conversation_reference in conv_dict.values():
AppCredentials.trust_service_url(conversation_reference.service_url)
try:
await asyncio.wait_for(_send_qptd_sep(cards, data, conversation_reference),
timeout=5)
except asyncio.TimeoutError:
pass
async def _send_qptd_sep(cards, data, conversation_reference):
await ADAPTER.continue_conversation(
conversation_reference,
lambda turn_context: turn_context.send_activities([
Activity(
text="bla bla bla",
type=ActivityTypes.message,
attachments=[CardFactory.adaptive_card(cards[0])]
),
Activity(
type=ActivityTypes.message,
attachments=[CardFactory.adaptive_card(cards[-1])]
)
]),
APP_ID,
)
我使用了这种超时方法,因为我担心通过向每个人发送问题会有一个损坏的 conversation_reference 的人,因此该方法会失败并且 for 循环不会继续。但无论如何,这些消息不会发送给所有人。预先感谢您的回答。
解决方案
推荐阅读
- reactjs - 当用户从反应 js 应用程序中的不同选项卡返回页面时调用函数
- ag-grid - 有人可以帮助我使用 ag-grid 的 tabToNextCell 方法的默认代码吗
- javascript - 动态表的可排序列(使用 DataTable 制作)
- laravel - 如何重置 Vue 组件?
- python - parts = func_name.split('.') TypeError: a bytes-like object is required, not 'str'
- c++ - CMake - 输出目录结构和 QML 模块
- java - Private Key is coming as Null from Keystore Object
- css - Angular & ng2-smart-table:多选模式复选框禁用
- visual-studio - RDLC Rectangle with tablix inside keep growing
- numpy - Fast algorithm for computing cofactor matrix