telega/testing/conversation

Declarative conversation testing DSL for integration testing bot flows.

import telega/testing/conversation

conversation.conversation_test()
|> conversation.send("/start")
|> conversation.expect_reply_containing("Hello")
|> conversation.send("/set_name")
|> conversation.expect_reply("What's your name?")
|> conversation.send("Alice")
|> conversation.expect_reply_containing("Alice")
|> conversation.run(router, fn() { Nil })

Types

Opaque type representing a sequence of conversation test steps.

pub opaque type ConversationTest

Values

pub fn conversation_test() -> ConversationTest

Creates a new empty conversation test.

pub fn expect_api_call(
  ct: ConversationTest,
  path_contains path_contains: String,
  body_contains body_contains: String,
) -> ConversationTest

Expects the next API call to have a path containing path_contains and a body containing body_contains.

pub fn expect_keyboard(
  ct: ConversationTest,
  buttons buttons: List(String),
) -> ConversationTest

Expects the next reply to include an inline keyboard containing all specified button texts.

pub fn expect_reply(
  ct: ConversationTest,
  text: String,
) -> ConversationTest

Expects the next reply to exactly match the given text.

pub fn expect_reply_containing(
  ct: ConversationTest,
  substring: String,
) -> ConversationTest

Expects the next reply to contain the given substring.

pub fn expect_reply_with_keyboard(
  ct: ConversationTest,
  containing substring: String,
  buttons buttons: List(String),
) -> ConversationTest

Expects the next reply to contain the given substring AND include a keyboard with specified buttons.

pub fn run(
  ct: ConversationTest,
  router: router.Router(session, error),
  default_session: fn() -> session,
) -> Nil

Runs the conversation test against a router with the given default session factory.

pub fn run_with(
  ct: ConversationTest,
  router_handler: fn(bot.Context(session, error), update.Update) -> Result(
    bot.Context(session, error),
    error,
  ),
  session_settings: bot.SessionSettings(session, error),
) -> Nil

Lower-level variant: runs the test with a custom router handler and session settings.

pub fn run_with_client(
  ct: ConversationTest,
  client: client.TelegramClient,
  calls: process.Subject(mock.ApiCall),
  router_handler: fn(bot.Context(session, error), update.Update) -> Result(
    bot.Context(session, error),
    error,
  ),
  session_settings: bot.SessionSettings(session, error),
) -> Nil

Runs the test with a custom client, calls subject, router handler, and session settings.

pub fn run_with_mock(
  ct: ConversationTest,
  router: router.Router(session, error),
  default_session: fn() -> session,
  client: client.TelegramClient,
  calls: process.Subject(mock.ApiCall),
) -> Nil

Runs the test with a custom mock client (e.g. from mock.routed_client).

pub fn send(
  ct: ConversationTest,
  text: String,
) -> ConversationTest

Sends a message. Text starting with / is auto-detected as a command. Command payloads are supported: /cmd payload here.

pub fn send_audio(ct: ConversationTest) -> ConversationTest

Sends an audio message with a default audio.

pub fn send_audio_with(
  ct: ConversationTest,
  audio: types.Audio,
) -> ConversationTest

Sends an audio message with custom audio.

pub fn send_callback(
  ct: ConversationTest,
  data: String,
) -> ConversationTest

Sends a callback query with the given data.

pub fn send_message(
  ct: ConversationTest,
  message: types.Message,
) -> ConversationTest

Sends a raw message update with a user-provided message.

pub fn send_photo(ct: ConversationTest) -> ConversationTest

Sends a photo message with a single default photo.

pub fn send_photo_with(
  ct: ConversationTest,
  photos: List(types.PhotoSize),
) -> ConversationTest

Sends a photo message with custom photos.

pub fn send_video(ct: ConversationTest) -> ConversationTest

Sends a video message with a default video.

pub fn send_video_with(
  ct: ConversationTest,
  video: types.Video,
) -> ConversationTest

Sends a video message with a custom video.

pub fn send_voice(ct: ConversationTest) -> ConversationTest

Sends a voice message with a default voice.

pub fn send_voice_with(
  ct: ConversationTest,
  voice: types.Voice,
) -> ConversationTest

Sends a voice message with custom voice.

Search Document