diff --git a/.github/workflows/gitleaks.yaml b/.github/workflows/gitleaks.yaml index c115f77..f20f0ad 100644 --- a/.github/workflows/gitleaks.yaml +++ b/.github/workflows/gitleaks.yaml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4.2.2 - name: Install the gitleaks run: wget https://github.com/zricethezav/gitleaks/releases/download/v8.15.2/gitleaks_8.15.2_linux_x64.tar.gz shell: pwsh @@ -21,18 +21,24 @@ jobs: continue-on-error: true - name: Setup NuGet.exe if: steps.gitleaks.outcome != 'success' - uses: nuget/setup-nuget@v1 + uses: nuget/setup-nuget@v2 with: nuget-version: latest - - name: Install the dotnet + - name: Install Mono if: steps.gitleaks.outcome != 'success' - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '3.1.x' + run: | + sudo apt update + sudo apt install -y mono-complete + - name: Install the dotnet SDK to a custom directory + if: steps.gitleaks.outcome != 'success' + run: | + mkdir -p $GITHUB_WORKSPACE/dotnet + curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --install-dir $GITHUB_WORKSPACE/dotnet --channel 6.0 - name: Install the report tool packages if: steps.gitleaks.outcome != 'success' run: | + export PATH=$GITHUB_WORKSPACE/dotnet:$PATH nuget install "Syncfusion.Email" -source ${{ secrets.NexusFeedLink }} -ExcludeVersion - dir $GITHUB_WORKSPACE/Syncfusion.Email/lib/netcoreapp3.1 - dotnet $GITHUB_WORKSPACE/Syncfusion.Email/lib/netcoreapp3.1/GitleaksReportMail.dll ${{ secrets.CITEAMCREDENTIALS }} "$GITHUB_REF_NAME" ${{ secrets.NETWORKCREDENTIALS }} ${{ secrets.NETWORKKEY }} "$GITHUB_WORKSPACE" ${{ secrets.ORGANIZATIONNAME }} - exit 1 \ No newline at end of file + dir $GITHUB_WORKSPACE/Syncfusion.Email/lib/net6.0 + dotnet $GITHUB_WORKSPACE/Syncfusion.Email/lib/net6.0/GitleaksReportMail.dll ${{ secrets.CITEAMCREDENTIALS }} "$GITHUB_REF_NAME" ${{ secrets.NETWORKCREDENTIALS }} ${{ secrets.NETWORKKEY }} "$GITHUB_WORKSPACE" ${{ secrets.ORGANIZATIONNAME }} + exit 1 diff --git a/AndroidChatApplication/AndroidChatApplication/Helpers/TwilioHelper.cs b/AndroidChatApplication/AndroidChatApplication/Helpers/TwilioHelper.cs index 50b7f16..6b2813c 100644 --- a/AndroidChatApplication/AndroidChatApplication/Helpers/TwilioHelper.cs +++ b/AndroidChatApplication/AndroidChatApplication/Helpers/TwilioHelper.cs @@ -13,8 +13,8 @@ public static async Task GetTokenAsync() { var deviceId = CrossDeviceInfo.Current.Id; const string twilioAccountSid = "AC3b4d9037a04f31c8e64fcd02ff2c6a9d"; - const string twilioApiKey = "SK797d3f329ea89c8d0a5eb7a27d92274d"; - const string twilioApiSecret = "B8mbBv19bFxRYZFv75dUFbmSsINeOd1x"; + const string twilioApiKey = " Use your own twilio Api Key"; + const string twilioApiSecret = "Use you own twilio Api Secret"; var identity = "Syncfusion"; var applicationName = "AndroidChatApplication"; diff --git a/README.md b/README.md index a3bfd26..d0bea2f 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,261 @@ This repository has a Chat application in Xamarin.Forms that is developed using Twilio. -# Prerequisites -Make sure that the necessary software is installed: +## Sample - Visual Studio 2019 with Xamarin +```xaml -## How to run the project +TwilioMessenger: -Step 1: Check out the sample project from the GitHub location to a location in your disk. + public class TwilioMessenger : Java.Lang.Object, ITwilioMessenger + { + private ChatClient chatClient; -Step 2: Open the solution file using the Visual Studio 2019. + public Com.Twilio.Chat.Message.Options MessageOptions; + public Channel chatChannel { get; private set; } -Step 3: Restore the NuGet packages by rebuilding the solution. + private List channelLists; -Step 5: Run the project. \ No newline at end of file + public TwilioMessenger() + { + App.ChatMessages = new ObservableCollection(); + App.ChannelDetails = new ObservableCollection(); + channelLists = new List(); + } + + /// + /// Setup the chat client + /// + /// + public async Task SetupAsync() + { + var task = new TaskCompletionSource(); + + //Get token to access the Twilio Account + + + // Initialization of chat client + ChatClient.Create(Android.App.Application.Context, + token, + (new ChatClient.ClientProperties.Builder()).CreateProperties(), + new ChatClientCallBackListener(this)); + Task.Delay(1000); + return await task.Task.ConfigureAwait(false); + } + + /// + /// Create the channel with chat client. + /// + /// + public void CreateChatChannel(ChatClient result) + { + chatClient = result; + MainActivity.GeneralChatClient = result; + + var friendlyName = "SyncfusionChannel"; + var channelType = Channel.ChannelType.Public; + // Create channels with channel type and friendly name. + chatClient.Channels.CreateChannel(friendlyName, channelType, + new CreateChannelCallBackListener(this)); + } + + /// + /// Join the Channel. + /// + /// + public void JoinChannel(Channel result) + { + chatChannel = result; + MainActivity.GeneralChannel = result; + chatChannel.Join(new ChatStatusListener(chatChannel)); + } + + /// + /// Get the channel Messages. + /// + /// + public void GetChannelMessagesList(Channel result) + { + chatChannel = result; + MainActivity.GeneralChannel = result; + MainActivity.GeneralChannel.AddListener(MainActivity.channelListener); + chatChannel.Messages.GetLastMessages(50, new MessagesListCallBackListener>()); + } + + public void SendMessage(string text, ObservableCollection ChatMessageInfo, Author CurrentUser) + { + chatChannel = MainActivity.GeneralChannel; + MessageOptions = Message.InvokeOptions().WithBody(text); + chatChannel.Messages.SendMessage(MessageOptions, new MessageCallBackListener()); + + MessagingCenter.Subscribe(this, "NewMessage", (sender, args) => + { + if (args != null && !App.IsMessageAdded) + { + App.ChatMessages.Add(new ChatMessage + { + Message = args.MessageBody, + Time = Convert.ToDateTime(args.DateCreated), + IsReceived = args.Author != MainActivity.GeneralChatClient.MyIdentity, + Identity = args.Author + }); + App.IsMessageAdded = true; + App.TypingMessage = null; + Application.Current.MainPage = new NavigationPage(new MessagePage()); + } + if(args.Author != MainActivity.GeneralChatClient.MyIdentity) + { + IsMemberTyping(); + } + else + { + App.TypingMessage = null; + } + }); + } + + public bool GetChatMessages() + { + var success = false; + App.ChatMessages = new ObservableCollection(); + var channels = MainActivity.PublicChannelsList; + var channelMessages = MainActivity.ChannelMessages; + foreach(var channel in channels) + { + if(channel.FriendlyName == App.FriendlyName) + { + MainActivity.GeneralChannel = channel; + if (channelMessages.Count > 0) + { + foreach (var channelMessage in channelMessages) + { + foreach (var message in channelMessage) + { + if (message.Channel.FriendlyName == App.FriendlyName) + { + success = true; + App.ChatMessages.Add(new ChatMessage + { + Message = message.MessageBody, + Time = Convert.ToDateTime(message.DateCreated), + IsReceived = message.Author != MainActivity.GeneralChatClient.MyIdentity, + Identity = message.Author + }); + } + success = true; + } + } + } + else + { + success = true; + } + } + } + App.TypingMessage = null; + return success; + } + + public bool GetAllPublicChannels() + { + var success = false; + App.ChannelDetails = new ObservableCollection(); + channelLists = new List(); + var channels = MainActivity.PublicChannelsList; + var channelMessages = MainActivity.ChannelMessages; + var selectedChannel = channelMessages.Select(a => a.Select(b => b.Channel).First()).ToList(); + if (channelMessages == null || channelMessages.Count == 0) + { + foreach(var channel in channels) + { + channelLists.Add(channel); + App.ChannelDetails.Add(new ChatDetail + { + SenderName = channel.FriendlyName, + MessageType = "Text", + Message = "", + Time = "", + NotificationType = "New" + }); + success = true; + } + } + else + { + foreach (var channelMessage in channelMessages) + { + foreach (var channel in channels) + { + var messageCount = channelMessage.Count; + var createdTime = Convert.ToDateTime(channelMessage[messageCount - 1].DateCreated); + var messageTime = DateTimeToStringConverter(createdTime); + if (channelMessage[0].Channel == channel) + { + channelLists.Add(channel); + App.ChannelDetails.Add(new ChatDetail + { + SenderName = channel.FriendlyName, + MessageType = "Text", + Message = channelMessage[messageCount - 1].MessageBody, + Time = messageTime, + NotificationType = "New" + }); + success = true; + } + else if (!channelLists.Contains(channel) && !selectedChannel.Contains(channel)) + { + channelLists.Add(channel); + App.ChannelDetails.Add(new ChatDetail + { + SenderName = channel.FriendlyName, + MessageType = "Text", + Message = "", + Time = "", + NotificationType = "Viewed" + }); + success = true; + } + } + } + } + return success; + } + + public string DateTimeToStringConverter(DateTime dateTime) + { + var currentTime = DateTime.Now; + + if (dateTime.Day == currentTime.Day) + { + return "Today"; + } + + return dateTime.Day == currentTime.AddDays(-1).Day ? "Yesterday" : dateTime.ToString("MMMM dd, yyyy", CultureInfo.CurrentCulture); + } + + public void IsMemberTyping() + { + MainActivity.GeneralChannel.Typing(); + } + + public bool IsValidURL(string uriName) + { + Uri uriResult; + bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); + return result; + } + } + +``` + +## Requirements to run the demo + +To run the demo, refer to [System Requirements for Xamarin](https://help.syncfusion.com/xamarin/system-requirements). + +## Troubleshooting + +### Path too long exception + +If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.