Example #1
0
        public async override Task Execute(Callback callback, IViberBotClient client)
        {
            TextMessage msg    = SendShedule(callback);
            long        result = await client.SendTextMessageAsync(msg);

            LeaguesCommand leaguesCommand = new LeaguesCommand(_leagueRepository, version);
            await leaguesCommand.Execute(callback, client);
        }
Example #2
0
        public async Task SendTextMessageAsyncTest()
        {
            var result = await _viberBotClient.SendTextMessageAsync(new TextMessage
            {
                Receiver = _adminId,
                Sender   = new UserBase
                {
                    Name = "Smbdy"
                },
                Text = "Hi!:)"
            });

            return;
        }
        public async Task SendTextMessageAsync(int botId, string receiverId, OutMessage message)
        {
            //
            if (message.Text == null)
            {
                throw new ArgumentNullException("text");
            }

            //
            var textMessage = new TextMessage
            {
                Receiver      = receiverId,
                MinApiVersion = 4,
                Text          = message.Text
            };

            await viberBotClient.SendTextMessageAsync(textMessage);
        }
Example #4
0
        public static async void SendNextMessage(DialogueFrame df, HealthBotContext ctx, users dbUser,
                                                 CallbackData callbackData, IViberBotClient client)
        {
            string   message = "";
            Keyboard keyboard;

            string[] buttons = null;

            if (df.Activity == EnumActivity.Unknown)
            {
                if (df.Entity != "")
                {
                    message = df.Entity;
                }
                else
                {
                    return;
                }
            }
            else
            {
                message = await GetNextMessage(df, dbUser, ctx, buttons);

                if (df.Activity == EnumActivity.CallHuman)
                {
                    dbUser.id_last_question        = null;
                    dbUser.is_last_question_system = null;
                    dbUser.chatting = "viber";
                }
                if (dbUser.is_last_question_system.HasValue)
                {
                    //если нужно прислать картинку
                    if (dbUser.is_last_question_system.Value == true && dbUser.id_last_question == (int)SystemMessages.SendBiomark_plot)
                    {
                        using (Stream stream = System.IO.File.OpenRead(dbUser.token + ".png"))
                        {
                            await client.SendPictureMessageAsync(
                                new PictureMessage()
                            {
                                Text          = "Ваш график",
                                Receiver      = callbackData.Sender.Id,
                                MinApiVersion = callbackData.Message.MinApiVersion,
                                TrackingData  = callbackData.Message.TrackingData,
                                Media         = "https://upload.wikimedia.org/wikipedia/commons/5/57/Viber-logo.png" //viber is lame
                            }
                                );
                        }
                        dbUser.id_last_question        = null;
                        dbUser.is_last_question_system = null;
                    }
                }
                if (message != "")
                {
                    dbUser.id_last_question = (int?)df.Tag;
                    if (buttons != null)
                    {
                        keyboard = new Keyboard()
                        {
                            BackgroundColor = "#32C832",
                            Buttons         = buttons.Select(t => new Viber.Bot.KeyboardButton()
                            {
                                Text = t
                            }).ToList()
                        };
                        await client.SendKeyboardMessageAsync(new KeyboardMessage
                        {
                            Text          = message,
                            Keyboard      = keyboard,
                            Receiver      = callbackData.Sender.Id,
                            MinApiVersion = callbackData.Message.MinApiVersion,
                            TrackingData  = callbackData.Message.TrackingData
                        });
                    }
                    else
                    {
                        await client.SendTextMessageAsync(new TextMessage()
                        {
                            Text          = message,
                            Receiver      = callbackData.Sender.Id,
                            MinApiVersion = callbackData.Message.MinApiVersion,
                            TrackingData  = callbackData.Message.TrackingData
                        });
                    }
                }
                else
                {
                    dbUser.id_last_question = null;
                }
            }
        }