Deduplicate the composed JSON payload construction — both the group and DM branches build the identical json.dumps result, so hoist it above the if/else to match the pattern already used in send().
Deduplicate the composed JSON payload construction — both the group and DM branches build the identical json.dumps result, so hoist it above the if/else to match the pattern already used in send().