Expanding the solution by @Dror Bogin you can use this expression together with array_foreach() to include not just two points, but any number of points - in the following example points 1 to 9 (first expression below):

In this case, you connect points in a regular order: 1,2,3,4... Changing the expression a bit, you can even define any arbitrary order of the points like from point 17 to 10 to 4 to 3 as can be seen on the next screenshot (second expression below):

First expression to connect points in a regular order, to be defined in line 4:
collect_geometries (
array_filter (
array_foreach (
generate_series (1,9), -- define here the list of $id's of the points to be included
line_substring(
$geometry,
line_locate_point(
$geometry,
closest_point(
$geometry,
geometry(get_feature_by_id ('points',@element))
)
),
line_locate_point(
$geometry,
closest_point(
$geometry,
geometry(get_feature_by_id ('points',@element+1))
)
)
)
),
@element IS NOT NULL
)
)
Second expression to connect points in any arbitrary order, to be defined in line 3:
with_variable (
'array',
array (17,10,4,3), -- define here the order in which the points should be connected
collect_geometries (
array_filter (
array_foreach (
@array,
line_substring(
$geometry,
line_locate_point(
$geometry,
closest_point(
$geometry,
geometry(get_feature_by_id ('points',@element))
)
),
line_locate_point(
$geometry,
closest_point(
$geometry,
geometry(get_feature_by_id ('points',array_get (@array,array_find (@array, @element)+1)))
)
)
)
),
@element IS NOT NULL
)
)
)