aboutsummaryrefslogtreecommitdiff
path: root/telegram/commands.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-11-24 20:10:29 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-11-24 20:10:29 +0300
commit653b1bde94b89d91862007a18b8730ff58673f59 (patch)
tree5b0c8674f918eb49dd27e53918ff10529c0ff55c /telegram/commands.go
parentc0c21a35a4cfd326423ad530926a0e96c1b07dcf (diff)
Telegram authorization
Diffstat (limited to 'telegram/commands.go')
-rw-r--r--telegram/commands.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/telegram/commands.go b/telegram/commands.go
new file mode 100644
index 0000000..64a5120
--- /dev/null
+++ b/telegram/commands.go
@@ -0,0 +1,33 @@
+package telegram
+
+const notEnoughArguments string = "Not enough arguments"
+const telegramNotInitialized string = "Telegram connection is not initialized yet"
+
+// ProcessTransportCommand executes commands sent directly to the component
+func (c *Client) ProcessTransportCommand(cmd string, args []string) string {
+ switch cmd {
+ case "login", "code", "password":
+ if cmd == "login" && c.Session.Login != "" {
+ return ""
+ }
+
+ if len(args) < 1 {
+ return notEnoughArguments
+ }
+ if c.authorizer == nil {
+ return telegramNotInitialized
+ }
+
+ switch cmd {
+ case "login":
+ c.authorizer.PhoneNumber <- args[0]
+ c.Session.Login = args[0]
+ case "code":
+ c.authorizer.Code <- args[0]
+ case "password":
+ c.authorizer.Password <- args[0]
+ }
+ }
+
+ return ""
+}