Telegram Plugin
TelegramPlugin
This plugin implements functions to send messages via Telegram.
Installation and settings​
info
Install the NuGet package:
- For .Net Core projects: WorkflowEngine.NETCore-TelegramPlugin.
- For .Net Framework projects: WorkflowEngine.NET-TelegramPlugin.
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​
Int32: a parameter for access to Telegram. For getting: register your application as a Telegram client.
Used for TelegramAuthentication.
ApiHash​
A parameter for access to Telegram. For getting: register your application as a Telegram client.
Used for TelegramAuthentication.
CodeRequest​
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()
{
// you can change code in debugger
string code = "myCode";
return code;
}
Read about Authentication.
SessionUserId​
String: the name of the session that tracks login info about this TelegramClient connection.
Used for TelegramAuthentication.
Number​
String: the number of the current User.
Used for TelegramAuthentication.
LimitMessageForRead​
Int32: the maximum number of messages that can be read at a time.
Default value: 100
Used for TelegramSendMessage
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
Used for TelegramSendMessage.
Actions​
Read about actions.
TelegramAuthentication​
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​
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​
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 messages 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​
To enable the plugin, the following should be done at the first start:
- Get ApiId and ApiHash; for getting register your application as a Telegram client.
- Connect your functions with the CodeRequest delegate.
- In the debugger mode, enter the code sent to you by SMS.
caution
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​
The type of the recipient identifier:
Value | Description |
---|---|
UserPhone | Phone Number. |
UserName | User Name. |
ChatTitle | Chat Title. |
ChannelTitle | Channel Title. |
SenderType​
The type of the sender identifier:
Value | Description |
---|---|
UserPhone | Phone Number. |
UserName | User Name. |
ChatTitle | Chat Title. |
ChannelTitle | Channel Title. |