Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/gitleaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public static async Task<string> 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";
Expand Down
259 changes: 251 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Channel> channelLists;

Step 5: Run the project.
public TwilioMessenger()
{
App.ChatMessages = new ObservableCollection<ChatMessage>();
App.ChannelDetails = new ObservableCollection<ChatDetail>();
channelLists = new List<Channel>();
}

/// <summary>
/// Setup the chat client
/// </summary>
/// <returns></returns>
public async Task<bool> SetupAsync()
{
var task = new TaskCompletionSource<bool>();

//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);
}

/// <summary>
/// Create the channel with chat client.
/// </summary>
/// <param name="chatClient"></param>
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<Channel>(this));
}

/// <summary>
/// Join the Channel.
/// </summary>
/// <param name="result"></param>
public void JoinChannel(Channel result)
{
chatChannel = result;
MainActivity.GeneralChannel = result;
chatChannel.Join(new ChatStatusListener(chatChannel));
}

/// <summary>
/// Get the channel Messages.
/// </summary>
/// <param name="result"></param>
public void GetChannelMessagesList(Channel result)
{
chatChannel = result;
MainActivity.GeneralChannel = result;
MainActivity.GeneralChannel.AddListener(MainActivity.channelListener);
chatChannel.Messages.GetLastMessages(50, new MessagesListCallBackListener<List<Message>>());
}

public void SendMessage(string text, ObservableCollection<object> ChatMessageInfo, Author CurrentUser)
{
chatChannel = MainActivity.GeneralChannel;
MessageOptions = Message.InvokeOptions().WithBody(text);
chatChannel.Messages.SendMessage(MessageOptions, new MessageCallBackListener<Message>());

MessagingCenter.Subscribe<ChannelListener, Message>(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<ChatMessage>();
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<ChatDetail>();
channelLists = new List<Channel>();
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.