TelegramPlugin

This plugin implements functions to send messages via Telegram.

Table of contents

  1. Installation and settings
  2. Settings
    1. ApiId
    2. ApiHash
    3. CodeRequest
    4. SessionUserId
    5. Number
    6. LimitMessageForRead
    7. MarkAsRead
  3. Actions
    1. TelegramAuthentication
    2. TelegramSendMessage
    3. TelegramListenMessages
  4. Elements
    1. Authentication
    2. GetterType
    3. SenderType

Installation and settings

Table of contents

Install the nuget package:

How to install nuget package in Visual studio for Windows

How to install nuget package in Visual studio for Mac

How install nuget package in Rider

Add the following namespaces to the usings section:

using OptimaJet.Workflow.Plugins;

Create a plugin object and arrange the required Settings:

var telegramPlugin = new TelegramPlugin();

// Here are your settings

// telegramPlugin.ApiId = "AccountSid";
// telegramPlugin.ApiHash = "AuthToken";
// telegramPlugin.CodeRequest += MyCodeRequest;
// telegramPlugin.SessionUserId = "AuthToken";
// telegramPlugin.Number = "AuthToken";
// telegramPlugin.LimitMessageForRead = 100;
// telegramPlugin.MarkAsRead = true;

Connect the plugin to the WorkflowRuntime:

var runtime = new WorkflowRuntime()...

runtime.WithPlugin(telegramPlugin);

Settings

ApiId

Table of contents

Int32: a parameter for access to Telegram. For getting: register your application as a Telegram client.

Used for TelegramAuthentication.

ApiHash

Table of contents

A parameter for access to Telegram. For getting: register your application as a Telegram client.

Used for TelegramAuthentication.

CodeRequest

Table of contents

A delegate, your function should return the code sent to you by SMS.

When the User is authenticated, a special file called session.dat will be created. In this file, the complete info about the User's session is stored. So, you should authenticate the User every time the session.dat file is corrupted or removed.

Action syntax:

string MyCodeRequest()
{
    string code = "myCode"; // you can change code in debugger

    return code;
}

Read about Authentication

SessionUserId

Table of contents

String: the name of the session that tracks login info about this TelegramClient connection.

Used for TelegramAuthentication.

Number

Table of contents

String: the number of the current User.

Used for TelegramAuthentication.

LimitMessageForRead

Table of contents

Int32: the maximum number of messages that can be read at a time.

Default value: 100

Used for TelegramSendMessage

MarkAsRead

Table of contents

Boolean: the flag to mark the received messages as already read: if true - a message is read; if false - a message remains unread.

Default value: true

Used for TelegramSendMessage

Actions

Read about actions.

TelegramAuthentication

Table of contents

Authentication of the current User.

Read about Authentication

Parameters:

ApiId : Int32 *

A parameter for access to Telegram. For getting: register your application as a Telegram client.

The value is taken from ApiId, if specified there.

ApiHash : String *

A parameter for access to Telegram. For getting: register your application as a Telegram client.

The value is taken from ApiHash, if specified there.

Number : String *

The number of the current User.

The value is taken from Number, if specified there.

SessionUserId : String *

The name of the session that tracks login info about this TelegramClient connection.

The value is taken from SessionUserId, if specified there.

TelegramSendMessage

Table of contents

Send a message to User / Chat / Channel.

Parameters:

GetterType : GetterType *

Specifies the type of the recipient identifier.

Default value: UserPhone

Getter : String *

The recipient identifier with the type specified in GetterType.

Message : String *

A string that contains the message body.

TelegramListenMessages

Table of contents

Receives new messages from от User / Chat / Channel.

Parameters:

SenderType : SenderType *

The type of the sender identifier, whose messages will be listened to.

Default value: UserPhone

Sender : String *

The sender identifier, whose messages will be listened to, with the type specified in SenderType.

ParameterName : String *

The name of the parameter, where new mwssages will be saved.

LimitMessageForRead : Int32 *

The maximum number of messages that can be read at a time.

Default value: 100

The value is taken from LimitMessageForRead, if specified there.

MarkAsRead : Boolean *

The flag to mark the received messages as already read: if true - a message is read; if false - a message remains unread.

Default value: true

The value is taken from MarkAsRead, if specified there.

Elements

Authentication

Table of contents

To enable the plugin, the following should be done at the first start:

  1. Get ApiId and ApiHash; for getting register your application as a Telegram client.
  2. Connect your functions with the CodeRequest delegate.
  3. In the debugger mode, enter the code sent to you by SMS.

When the User is authenticated, a special file called session.dat will be created. In this file, the complete info about the User's session is stored. So, you should authenticate the User every time the session.dat file is corrupted or removed.

GetterType

Table of contents

The type of the recipient identifier:

Value Description
UserPhone Phone Number.
UserName User Name.
ChatTitle Chat Title.
ChannelTitle Channel Title.

SenderType

Table of contents

The type of the sender identifier:

Value Description
UserPhone Phone Number.
UserName User Name.
ChatTitle Chat Title.
ChannelTitle Channel Title.
Top