Telefunc 0.1.1

dotnet add package Telefunc --version 0.1.1                
NuGet\Install-Package Telefunc -Version 0.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Telefunc" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Telefunc --version 0.1.1                
#r "nuget: Telefunc, 0.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Telefunc as a Cake Addin
#addin nuget:?package=Telefunc&version=0.1.1

// Install Telefunc as a Cake Tool
#tool nuget:?package=Telefunc&version=0.1.1                

Telefunc

The functional wrapping library of Telegram.Bot wrote in F#.

Roadmap

  • 0.0.1

    • Starting point 😃
  • 0.1 (we are here)

    1. ✅ runBot function;
    2. ✅ tree-like bot's handlers structure;
    3. ✅ basic wrapped functions for sending messages;
    4. ✅ states machine;
    5. ✅ helper function getId: Update -> int64 option.
  • 0.2

    1. more updates-filtering functions for handlers;
    2. more Telegram.Bot wrapped functions and types.
  • 0.3

    1. more comfortable state-machine mechanism;

    ... there will be more ...

Examples

HelloWorld.fsx

#r "nuget: Telefunc, 0.1.0"

open Telefunc.Core
open Telegram.Bot.Types
open Telegram.Bot
open Telegram.Bot.Exceptions
open System.Threading.Tasks

exception ApiRequestException_fs of ApiRequestException

let handlePollingErrorAsync _ ex _ =
    task {
        printfn "%A"
        <| match ex with
            | ApiRequestException_fs apiReqException ->
                $"Telegram API Error:\n[{apiReqException.ErrorCode}]\n{apiReqException.Message}"
            | _ -> ex.ToString()
    } :> Task

let inline sayHello name (bot: ITelegramBotClient) (update: Update) =
    Wrappers.sendMessage(
        bot = bot,
        chatId = update.Message.Chat.Id,
        text = $"Hello {name}!",
        insteadOfMsg = None )

let sayHelloWorld bot update =
    sayHello "World" bot update |> ignore
    true

let sayHelloToUser (bot: ITelegramBotClient) (update: Update) =
    sayHello update.Message.Chat.FirstName bot update |> ignore
    true

let help (bot: ITelegramBotClient) (update: Update) =
    Wrappers.sendMessage(
        bot = bot,
        chatId = update.Message.Chat.Id,
        text = "Welcome to Hello World bot!\n\nCommands:\n/start\n/help\n\nWrite \"Hello\" to me and I will respond!",
        insteadOfMsg = None ) |> ignore
    true

runBot
    "TOKEN"
    [
        Filter.command [
            Filter.commandName "start" [ sayHelloWorld ]
            Filter.commandName "help" [ help ]
        ]
        Filter.message [
            Filter.justText "Hello" [ sayHelloToUser ]
        ]
    ]
    handlePollingErrorAsync
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 133 2/15/2024
0.1.0 118 1/19/2024