Using Matchers with Effect Generators in Typescript

Hi guys, I am trying to write a program that does different things based on a different pattern. But cannot really figure out how matchers work from the docs and if they can be used inside generators? The sendInfobipTextMessage also returns a Effect and I want to run the program like program.pipe(Effect.runPromise) any help would be appreciated! 😀

  const program = Effect.gen(function* () {
    const channel = yield* getChannelById(ctx, {
      userOrganizationId: ctx.user.defaultOrganizationId!,
      channelId: args.channelId,
    });

    const destination = yield* getDestinationById(ctx, {
      userOrganizationId: ctx.user.defaultOrganizationId!,
      destinationId: args.destinationId,
    });
    const matcher = Match.value({ channel, args, destination }).pipe(
      // infobip text message
      Match.when(
        {
          channel: {
            type: "infobip:whatsapp",
          },
          args: {
            infobip: {
              whatsappTextMessage: (x) => !!x,
            },
          },
        },
        ({ channel, destination, args }) => {
          // send infobip text message
          return sendInfobipTextMessage(ctx, {
            textMessage: args.infobip.whatsappTextMessage,
            channel,
            destination,
            userId: ctx.user._id,
          });
        },
      ),
      // ...
    );
    return yield* Effect.asVoid(matcher);
  });
Was this page helpful?