Hello everyone! There is a code below, how can I make it so that when clicking on new_button_1, the data from input is sent by the post method to the server https://api.example.com
import {
IAppAccessors,
IConfigurationExtend,
ILogger,
IRead,
IModify,
IHttp,
IPersistence,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import { ISlashCommand, SlashCommandContext } from '@rocket.chat/apps-engine/definition/slashcommands';
import {
IUIKitInteractionHandler,
UIKitBlockInteractionContext,
UIKitSurfaceType,
} from '@rocket.chat/apps-engine/definition/uikit';
export class CyApp extends App implements IUIKitInteractionHandler {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
protected async extendConfiguration(configuration: IConfigurationExtend): Promise<void> {
await configuration.slashCommands.provideSlashCommand(new OpenModalCommand(this));
}
public async executeBlockActionHandler(
context: UIKitBlockInteractionContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify,
) {
const data = context.getInteractionData();
if (data.actionId === 'button_1') {
const bb = modify.getCreator().getBlockBuilder();
bb.addSectionBlock({
blockId: 'new_section',
text: bb.newPlainTextObject('New buttons after button_1 clicked'),
});
bb.addInputBlock({
blockId: 'subject_input',
element: bb.newPlainTextInputElement({
actionId: 'subject_action',
placeholder: bb.newPlainTextObject('Enter subject'),
}),
label: bb.newPlainTextObject('Subject'),
});
bb.addInputBlock({
blockId: 'description_input',
element: bb.newPlainTextInputElement({
actionId: 'description_action',
placeholder: bb.newPlainTextObject('Enter description'),
multiline: true,
}),
label: bb.newPlainTextObject('Description'),
});
bb.addActionsBlock({
blockId: 'new_buttons_row',
elements: [
bb.newButtonElement({
actionId: 'new_button_1',
text: bb.newPlainTextObject('New Button 1'),
value: 'new_btn1',
}),
bb.newButtonElement({
actionId: 'new_button_2',
text: bb.newPlainTextObject('New Button 2'),
value: 'new_btn2',
}),
],
});
await modify.getUiController().updateSurfaceView(
{
id: 'modal-id',
type: UIKitSurfaceType.MODAL,
title: { type: 'plain_text', text: 'Updated SCORE' },
blocks: bb.getBlocks(),
},
{ triggerId: data.triggerId! },
data.user,
);
return context.getInteractionResponder().successResponse();
}
// return context.getInteractionResponder().successResponse();
}
}
class OpenModalCommand implements ISlashCommand {
public command = 'score';
public i18nParamsExample = 'slashcommand_params';
public i18nDescription = 'slashcommand_description';
public providesPreview = false;
constructor(private readonly app: App) {}
public async executor(context: SlashCommandContext, _read: IRead, modify: IModify): Promise<void> {
const bb = modify.getCreator().getBlockBuilder();
bb.addSectionBlock({
blockId: 'section_1',
text: bb.newPlainTextObject('Нажми на интересующий вопрос', true),
});
bb.addActionsBlock({
blockId: 'buttons_row_1',
elements: [
bb.newButtonElement({ actionId: 'button_1', text: bb.newPlainTextObject('Text 1'), value: 'btn1' }),
bb.newButtonElement({ actionId: 'button_2', text: bb.newPlainTextObject('Text 2'), value: 'btn2' }),
bb.newButtonElement({ actionId: 'button_3', text: bb.newPlainTextObject('Text 3'), value: 'btn3' }),
],
});
bb.addActionsBlock({
blockId: 'buttons_row_2',
elements: [
bb.newButtonElement({ actionId: 'button_4', text: bb.newPlainTextObject('Text 4'), value: 'btn4' }),
bb.newButtonElement({ actionId: 'button_5', text: bb.newPlainTextObject('Text 5'), value: 'btn5' }),
bb.newButtonElement({ actionId: 'button_6', text: bb.newPlainTextObject('Text 6'), value: 'btn6' }),
],
});
await modify.getUiController().openSurfaceView(
{
id: 'modal-id',
type: UIKitSurfaceType.MODAL,
title: { text: 'SCORE', type: 'plain_text' },
blocks: bb.getBlocks(),
},
{ triggerId: context.getTriggerId()! },
context.getSender(),
);
}
}