private void InitViews() { UserMessage = FindViewById <EditText>(Resource.Id.main_inputmessage_edittext); SendButton = FindViewById <Button>(Resource.Id.main_send_floatingactionbutton); MessagesRecycler = FindViewById <RecyclerView>(Resource.Id.main_message_listview); TextInputLayout = FindViewById <RelativeLayout>(Resource.Id.main_textinput_layout); ButtonsInputLayout = FindViewById <HorizontalScrollView>(Resource.Id.main_buttoninput_layout); InputArea = FindViewById <LinearLayout>(Resource.Id.main_inputmessage_layout); Adapter = new ChatAdapter(MessagesList); var layoutManager = new LinearLayoutManager(this); layoutManager.ReverseLayout = true; layoutManager.StackFromEnd = true; MessagesRecycler.SetLayoutManager(layoutManager); MessagesRecycler.SetAdapter(Adapter); SendButton.Enabled = false; SetInputLayout(true); var activity = new Microsoft.Bot.Connector.DirectLine.Activity("message", text: "Hey, my name is Thuan, I'll help you get this claim sorted out in no time...", fromProperty: new Microsoft.Bot.Connector.DirectLine.ChannelAccount { Id = BotConnector.BotId }); AddMessageToList(activity); }
static async Task MainAsync() { var key = ConfigurationManager.AppSettings["BotKey"]; NotificationSender notificationSender = new NotificationSender(key); IList <Party> partiesToNotify = new List <Party>(); var party = PartyManager.GetParties()[0]; partiesToNotify.Add(party); Console.WriteLine("Write Notification. Your Message, High|Normal|Low"); Console.Write("> "); var messageLine = Console.ReadLine(); var message = messageLine.Split(','); while (message[0].ToLower() != "stop") { Log($"Sending notification {message[0]}"); Microsoft.Bot.Connector.DirectLine.ResourceResponse resourceResponse = await notificationSender.NotifyAsync(partiesToNotify, $"{message[0]}", message[1].ToLower().Trim()); Log($"{((resourceResponse == null) ? "Received no response" : $"Received resource response with ID {resourceResponse.Id}")}"); Console.Write("> "); messageLine = Console.ReadLine(); message = messageLine.Split(','); #if DEBUG // The following will dump the activity info into Output (console) Microsoft.Bot.Connector.DirectLine.Activity activity = await notificationSender.GetLatestReplyAsync(); #endif }
private void AddButtons(List <AttachmentButton> attachmentButtons) { var layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); layoutParams.Weight = 1; layoutParams.SetMargins(4, 2, 4, 2); foreach (var attachmentButton in attachmentButtons) { var button = new Button(this) { TransformationMethod = null, Text = attachmentButton.Title, LayoutParameters = layoutParams, }; button.SetPadding(4, 2, 4, 2); var drawable = Resources.GetDrawable(Resource.Drawable.button_rounded); button.Background = drawable; button.Click += async(sender, e) => { InputArea.RemoveAllViews(); var activity = new Microsoft.Bot.Connector.DirectLine.Activity(type: "message", text: button.Text, fromProperty: new Microsoft.Bot.Connector.DirectLine.ChannelAccount { Id = Android.Provider.Settings.Secure.AndroidId }); AddMessageToList(activity); await SendMessage(button.Text); }; InputArea.AddView(button); } }
static async Task MainAsync() { NotificationSender notificationSender = new NotificationSender("INSERT YOUR DIRECT LINE SECRET HERE"); IList <Party> partiesToNotify = new List <Party>(); /* * You can set the parties to notify here. In order to do that you need to access the * database of users collected by the bot somehow. You could also send a backchannel * message to the bot asking for suitable parties. However, that is not the point of * this sample so I will leave the implementation to you. */ for (int i = 0; i < NumberOfNotificationsToSend; ++i) { Log($"Sending notification {(i + 1)}/{NumberOfNotificationsToSend}..."); Microsoft.Bot.Connector.DirectLine.ResourceResponse resourceResponse = await notificationSender.NotifyAsync(partiesToNotify, $"Notification test {(i + 1)}"); Log($"{((resourceResponse == null) ? "Received no response" : $"Received resource response with ID {resourceResponse.Id}")}"); #if DEBUG // The following will dump the activity info into Output (console) Microsoft.Bot.Connector.DirectLine.Activity activity = await notificationSender.GetLatestReplyAsync(); #endif Thread.Sleep(3000); }
public static AttachmentType CheckTypeOfMessage(Microsoft.Bot.Connector.DirectLine.Activity message) { switch (message.AttachmentLayout) { case "list": return(AttachmentType.List); default: return(AttachmentType.None); } }
private async Task SendMessage(string message) { TextInputLayout.Visibility = ViewStates.Gone; ButtonsInputLayout.Visibility = ViewStates.Gone; var activity = new Microsoft.Bot.Connector.DirectLine.Activity("message", text: "...", fromProperty: new Microsoft.Bot.Connector.DirectLine.ChannelAccount { Id = BotConnector.BotId }); AddMessageToList(activity); await BotConnector.SendMessage(message); var result = await BotConnector.GetMessages(); UpdateListMessages(result.ToList()); }
private async void SendButton_Click(object sender, EventArgs e) { if (_datePicker == true) { UserMessage.FocusableInTouchMode = true; UserMessage.Click -= UserMessage_Click; } HideKeyboard(); var message = UserMessage.Text; UserMessage.Text = string.Empty; var activity = new Microsoft.Bot.Connector.DirectLine.Activity("message", text: message, fromProperty: new Microsoft.Bot.Connector.DirectLine.ChannelAccount { Id = Android.Provider.Settings.Secure.AndroidId }); AddMessageToList(activity); await SendMessage(message); }
private void AddMessageToList(Microsoft.Bot.Connector.DirectLine.Activity message) { MessagesList.Insert(0, message); Adapter.NotifyItemInserted(0); MessagesRecycler.ScrollToPosition(0); }