Пример #1
0
def parse_answer_view() -> Tuple[str, List[str]]:
    metadata = action_metadata.get()
    assert metadata and metadata.view, 'Must be called from view context'

    q_id = metadata.view['private_metadata']
    answers = []
    for num in range(1, MAX_QUESTIONS + 1):
        block = metadata.view['state']['values'].get(f'answer_{num}')
        if block is None:
            break
        answers.append(block[ANSWER_INPUT_ACTION_ID.format(num)].get('value'))

    return q_id, answers
Пример #2
0
def parse_creation_view() -> Tuple[str, List[str], List[str]]:
    metadata = action_metadata.get()
    assert metadata and metadata.view, 'Must be called from view context'

    values = metadata.view['state']['values']
    title = values['title'][TITLE_INPUT_ACTION_ID]['value']
    recipients = (
        values['recipients'][RECIPIENTS_SELECT_ACTION_ID]['selected_users'])
    questions = []
    for num in range(1, MAX_QUESTIONS + 1):
        block = values.get(f'question_{num}')
        if block is None:
            break
        question = block[QUESTION_INPUT_ACTION_ID.format(num)].get('value')
        if question is not None:
            questions.append(question)

    return title, recipients, questions
Пример #3
0
async def open_answer_view(collection: AsyncIOMotorCollection,
                           q_id: str) -> None:
    metadata = action_metadata.get()
    assert metadata and metadata.actions, 'Must be called from action context'

    questionnaire = await get_questionnaire_by_id(collection, q_id)
    assert questionnaire is not None, "Couldn't find questionnaire by _id"

    user = get_current_user_id()
    if user not in _get_not_answered_recipients(questionnaire):
        return await send_ephemeral(
            'You have already sent your feedback on this questionnaire.')

    await async_slack_request(method='views_open',
                              payload={
                                  'trigger_id':
                                  metadata.trigger_id,
                                  'view':
                                  build_answer_view(questionnaire['title'],
                                                    questionnaire['questions'],
                                                    q_id)
                              })
Пример #4
0
async def get_module_name_from_button() -> str:
    metadata = action_metadata.get()
    assert metadata and metadata.actions, 'Must be called from action context'

    action = metadata.actions[0]
    return action['value']
Пример #5
0
async def get_q_id_from_button() -> str:
    metadata = action_metadata.get()
    assert metadata and metadata.actions, 'Must be called from action context'
    return metadata.actions[0]['value']