Skip to content

Commit

Permalink
Merge pull request #24 from loyldg/feat/layer-177
Browse files Browse the repository at this point in the history
Feat/layer 177
  • Loading branch information
loyldg authored Apr 20, 2024
2 parents c09dc40 + c416f47 commit 6ac90c1
Show file tree
Hide file tree
Showing 1,627 changed files with 30,362 additions and 17,902 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# MyTelegram

[![API Layer](https://img.shields.io/badge/API_Layer-174-blueviolet)](https://corefork.telegram.org/methods)
[![API Layer](https://img.shields.io/badge/API_Layer-177-blueviolet)](https://corefork.telegram.org/methods)
[![MTProto](https://img.shields.io/badge/MTProto_Protocol-2.0-green)](https://corefork.telegram.org/mtproto/)
[![Support Chat](https://img.shields.io/badge/Chat_with_us-on_Telegram-0088cc)](https://t.me/+S-aNBoRvCRpPyXrR)

MyTelegram is [Telegram server side api](https://core.telegram.org/api) implementation written in c#,support private deployment
MyTelegram is telegram server side api implementation written in c#,support private deployment

## Features

- API Layer: **`174`**
- API Layer: **`177`**
- [MTProto transports](https://corefork.telegram.org/mtproto/mtproto-transports): **`Abridged`**,**`Intermediate`**
- Private chat
- Group chat
Expand Down Expand Up @@ -49,7 +49,7 @@ build\docker\5.build-gateway-server.sh
https://github.com/loyldg/mytelegram/blob/dev/docker/compose/docker-compose.yml
https://github.com/loyldg/mytelegram/blob/dev/docker/compose/.env
```
2. Change the IP address in **.env**,replace `192.168.1.100` with the IP address of gateway server
2. Replace `192.168.1.100` with your own server IP in `.env`
3. Run the following command in the directory where the docker-compose.yml file is located
```
docker compose up
Expand All @@ -62,8 +62,8 @@ build\docker\5.build-gateway-server.sh
3. Install MongoDB
4. Intall RabbitMQ
5. Install Minio
6. Modify server configuration in `start-all.bat`/`start-all.sh`,replace `192.168.1.100` with the IP address of gateway server
7. Run `start-all.bat`/`start-all.sh`
6. Replace `192.168.1.100` with your own server IP in `start-all.bat`
7. Run `start-all.bat`
8. Run telegram client
4. Default verification code is `22222`

Expand Down
2 changes: 1 addition & 1 deletion build/build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version="0.19.229"
$version="0.20.420"
$currentDir=(Get-Item .).FullName
$parentFolder=(Get-Item $currentDir).Parent
$outputRootFolder=Join-Path $parentFolder "out" $version
Expand Down
2 changes: 1 addition & 1 deletion build/docker/get-version.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
currentDate=`date +%-m%d`
#imageVersion=0.6.$currentDate
version=0.19.$currentDate
version=0.20.$currentDate
imageVersion=$version-alpine
echo version: $version
echo image version: $imageVersion
11 changes: 10 additions & 1 deletion docker/compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TempAuthKeyExpirationMinutes=720
# https://corefork.telegram.org/api/auth#future-auth-tokens
EnableFutureAuthToken=true
SetPremiumToTrueAfterUserCreated=true
SendWelcomeMessageAfterUserSignIn=true
SendWelcomeMessageAfterUserSignIn=false
AutoCreateSuperGroup=true

# Gateway server
Expand Down Expand Up @@ -111,13 +111,22 @@ DcOptions1Ipv6=false

# The verifycation code(Must be numeric),if the value is empty,the server will generate a random code
FixedVerifyCode=22222
VerificationCodeLength=4
VerificationCodeExpirationSeconds=300

# Twilio sms service configuration
TwilioSmsEnabled=false
# TwilioSmsAccountSId=
# TwilioSmsAuthToken=
# TwilioSmsFromNumber=

# VonageSms sms
VonageSmsEnabled=false
# VonageSmsBrandName=
# VonageSmsApiKey=
# VonageSmsApiSecret=


# Mongodb connectionString
DefaultConnectionStrings=mongodb://mongodb:27017

Expand Down
10 changes: 9 additions & 1 deletion docker/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ services:
App__DcOptions__1__Port: ${DcOptions1Port}
App__DcOptions__1__Ipv6: ${DcOptions1Ipv6}
App__FixedVerifyCode: ${FixedVerifyCode}
App__VerificationCodeLength: ${VerificationCodeLength}
App__VerificationCodeExpirationSeconds: ${VerificationCodeExpirationSeconds}
App__DatabaseName: ${DatabaseName}
App__QueryServerEventStoreDatabaseName: ${QueryServerEventStoreDatabaseName}
App__QueryServerReadModelDatabaseName: ${QueryServerReadModelDatabaseName}
Expand Down Expand Up @@ -280,6 +282,8 @@ services:
App__DcOptions__1__Port: ${DcOptions1Port}
App__DcOptions__1__Ipv6: ${DcOptions1Ipv6}
App__FixedVerifyCode: ${FixedVerifyCode}
App__VerificationCodeLength: ${VerificationCodeLength}
App__VerificationCodeExpirationSeconds: ${VerificationCodeExpirationSeconds}
App__DatabaseName: ${DatabaseName}
App__QueryServerEventStoreDatabaseName: ${QueryServerEventStoreDatabaseName}
App__QueryServerReadModelDatabaseName: ${QueryServerReadModelDatabaseName}
Expand Down Expand Up @@ -311,7 +315,11 @@ services:
TwilioSms__AccountSId: ${TwilioSmsAccountSId}
TwilioSms__AuthToken: ${TwilioSmsAuthToken}
TwilioSms__FromNumber: ${TwilioSmsFromNumber}

VonageSms__Enabled: ${VonageSmsEnabled}
VonageSms__BrandName: ${VonageSmsBrandName}
VonageSms__ApiKey: ${VonageSmsApiKey}
VonageSms__ApiSecret: ${VonageSmsApiSecret}

volumes:
- ./data/mytelegram/sms-sender/logs:/data/Logs
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!-- <VersionSuffix>0.6.$([System.DateTime]::Now.ToString(MMdd)).$([System.DateTime]::Now.ToString("HHmm"))</VersionSuffix> -->
<VersionSuffix>0.18.$([System.DateTime]::Now.ToString("Mdd"))</VersionSuffix>
<VersionSuffix>0.20.$([System.DateTime]::Now.ToString("Mdd"))</VersionSuffix>
<AssemblyVersion Condition="'$(VersionSuffix)' =='' ">0.0.0.1</AssemblyVersion>
<AssemblyVersion Condition="'$(VersionSuffix)' !='' ">$(VersionSuffix)</AssemblyVersion>
<Version Condition="'$(VersionSuffix)' =='' ">0.0.1.0</Version>
Expand Down
2 changes: 2 additions & 0 deletions source/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0-preview-23424-02" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="[1.19.6-Preview.1, 1.19.6]" />
<PackageVersion Include="Polly" Version="8.2.0" />
Expand All @@ -44,6 +45,7 @@
<PackageVersion Include="Volo.Abp.Autofac" Version="7.4.0-rc.4" />
<PackageVersion Include="Volo.Abp.EventBus.RabbitMQ" Version="7.4.0-rc.4" />
<PackageVersion Include="Volo.Abp.Sms" Version="7.4.0-rc.4" />
<PackageVersion Include="Vonage" Version="7.2.0" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.1" />
</ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions source/MyTelegram.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTelegram.Services", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTelegram.EventBus.Rebus", "src\MyTelegram.EventBus.Rebus\MyTelegram.EventBus.Rebus.csproj", "{110740FE-D600-41EF-8BF3-5115D23E00F9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyTelegram.EventFlow", "src\MyTelegram.EventFlow\MyTelegram.EventFlow.csproj", "{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyTelegram.TestApp", "src\MyTelegram.TestApp\MyTelegram.TestApp.csproj", "{8D070E04-ABCE-439F-A7A9-864D73225D34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -201,6 +205,14 @@ Global
{110740FE-D600-41EF-8BF3-5115D23E00F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{110740FE-D600-41EF-8BF3-5115D23E00F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{110740FE-D600-41EF-8BF3-5115D23E00F9}.Release|Any CPU.Build.0 = Release|Any CPU
{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5}.Release|Any CPU.Build.0 = Release|Any CPU
{8D070E04-ABCE-439F-A7A9-864D73225D34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D070E04-ABCE-439F-A7A9-864D73225D34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D070E04-ABCE-439F-A7A9-864D73225D34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D070E04-ABCE-439F-A7A9-864D73225D34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -240,6 +252,8 @@ Global
{ACCB7A7F-19E2-4593-B6A0-97989D6B78E6} = {DB4DF262-E785-497F-B465-440175026F97}
{0A9D2AE0-F943-408E-B740-2101DDF865CE} = {DB4DF262-E785-497F-B465-440175026F97}
{110740FE-D600-41EF-8BF3-5115D23E00F9} = {5F3FB626-5C24-4663-9B74-C9257417305E}
{D4E1CD1A-EA33-48B8-A965-D55F82CCFBC5} = {EB17BE1D-A92C-49B5-BFF1-DD75BC7DC94B}
{8D070E04-ABCE-439F-A7A9-864D73225D34} = {DB4DF262-E785-497F-B465-440175026F97}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8E7A112-1B80-4DCC-9884-5069D0E3B651}
Expand Down
26 changes: 10 additions & 16 deletions source/src/MyTelegram.Caching.Redis/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@

namespace MyTelegram.Caching.Redis;

public class CacheManager<TCacheItem> : ICacheManager<TCacheItem> where TCacheItem : class
public class CacheManager<TCacheItem>(
IDistributedCache distributedCache,
ICacheSerializer cacheSerializer)
: ICacheManager<TCacheItem>
where TCacheItem : class
{
private readonly ICacheSerializer _cacheSerializer;
private readonly IDistributedCache _distributedCache;

public CacheManager(IDistributedCache distributedCache,
ICacheSerializer cacheSerializer)
{
_distributedCache = distributedCache;
_cacheSerializer = cacheSerializer;
}

public async Task<TCacheItem?> GetAsync(string key)
{
var cachedBytes = await _distributedCache.GetAsync(key);
var cachedBytes = await distributedCache.GetAsync(key);
if (cachedBytes == null)
{
return default;
}

return _cacheSerializer.Deserialize<TCacheItem?>(cachedBytes);
return cacheSerializer.Deserialize<TCacheItem?>(cachedBytes);
//return JsonSerializer.Deserialize<TCacheItem>(Encoding.UTF8.GetString(cachedBytes), _jsonSerializerOptions);
}

Expand All @@ -46,7 +40,7 @@ public async Task<IDictionary<string, TCacheItem>> GetManyAsync(IReadOnlyList<st

public Task RemoveAsync(string key)
{
return _distributedCache.RemoveAsync(key);
return distributedCache.RemoveAsync(key);
}

public Task SetAsync(string key,
Expand All @@ -70,7 +64,7 @@ public Task SetAsync(string key,
}

//var bytes = JsonSerializer.SerializeToUtf8Bytes(value, _jsonSerializerOptions);
var bytes = _cacheSerializer.Serialize(value);
return _distributedCache.SetAsync(key, bytes, cacheOptions);
var bytes = cacheSerializer.Serialize(value);
return distributedCache.SetAsync(key, bytes, cacheOptions);
}
}
9 changes: 2 additions & 7 deletions source/src/MyTelegram.Caching.Redis/CacheSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

namespace MyTelegram.Caching.Redis;

public class CacheSerializer : ICacheSerializer
public class CacheSerializer(JsonSerializerOptions options) : ICacheSerializer
{
private readonly JsonSerializerOptions _options;

public CacheSerializer(JsonSerializerOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
}
private readonly JsonSerializerOptions _options = options ?? throw new ArgumentNullException(nameof(options));

public byte[] Serialize<T>(T obj)
{
Expand Down
21 changes: 4 additions & 17 deletions source/src/MyTelegram.Core/DefaultObjectMapper.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
namespace MyTelegram.Core;

public class DefaultObjectMapper<TContext> : DefaultObjectMapper, IObjectMapper<TContext>
{
public DefaultObjectMapper(
IServiceProvider serviceProvider
) : base(
serviceProvider)
{
}
}
public class DefaultObjectMapper<TContext>(IServiceProvider serviceProvider)
: DefaultObjectMapper(serviceProvider), IObjectMapper<TContext>;

public class DefaultObjectMapper : IObjectMapper //, ITransientDependency
public class DefaultObjectMapper(IServiceProvider serviceProvider) : IObjectMapper //, ITransientDependency
{
public DefaultObjectMapper(
IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}

protected IServiceProvider ServiceProvider { get; }
protected IServiceProvider ServiceProvider { get; } = serviceProvider;

[return: NotNullIfNotNull("source")]
public virtual TDestination? Map<TSource, TDestination>(TSource source)
Expand Down
2 changes: 1 addition & 1 deletion source/src/MyTelegram.Core/IRandomHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface IRandomHelper
{
string GenerateRandomString(int length);

string GenerateRandomNumber(int length);
void NextBytes(byte[] buffer);

byte[] NextBytes(int length);
Expand Down
25 changes: 13 additions & 12 deletions source/src/MyTelegram.Core/RandomHelper.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
namespace MyTelegram.Core;

public class RandomHelper : IRandomHelper//, ISingletonDependency
public class RandomHelper : IRandomHelper
{
private const string Characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private const string NumberCharacters = "0123456789";
public string GenerateRandomNumber(int length)
{
return new(Enumerable.Repeat(NumberCharacters, length)
.Select(s => s[Random.Shared.Next(s.Length)]).ToArray());
}

public string GenerateRandomString(int length)
{
return new(Enumerable.Repeat(Characters, length)
.Select(s => s[Random.Shared.Next(s.Length)]).ToArray());
}

public void NextBytes(byte[] buffer)
{
//_rng.GetBytes(buffer);
//ThreadLocalRandom.NextBytes(buffer);
Random.Shared.NextBytes(buffer);
}

public byte[] NextBytes(int length)
{
var buffer = new byte[length];
//_rng.GetBytes(buffer);
//ThreadLocalRandom.NextBytes(buffer);
Random.Shared.NextBytes(buffer);

return buffer;
}

public string GenerateRandomString(int length)
{
return new(Enumerable.Repeat(Characters, length)
.Select(s => s[Random.Shared.Next(s.Length)]).ToArray());
}

public int NextInt(int min,
int max)
{
Expand Down
4 changes: 4 additions & 0 deletions source/src/MyTelegram.Core/TransportErrorEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace MyTelegram.Core;

public partial record TransportErrorEvent(long AuthKeyId,
string ConnectionId, int TransportErrorCode);
4 changes: 3 additions & 1 deletion source/src/MyTelegram.Domain.Shared/MessageActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ public enum MessageActionType
SecureValuesSent,
SecureValuesSentMe,
SetMessagesTtl,
ChannelAddUser
ChannelAddUser,
ForumTopicCreated,
ForumTopicEdited,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ namespace MyTelegram;

public class MyTelegramServerDomainConsts
{
public const int Layer = 174;
public const int Layer = 177;

public const string RepositoryUrl = "https://github.com/loyldg/mytelegram";
public const long UserIdInitId = 2000000;
public const long ChatIdInitId = 50000000000;
public const long ChannelInitId = 800000000000;
public const long BotUserInitId = 90000000000000;
public const int PtsInitId = 1;

public const long OfficialUserId = 777000;

public const long DeletedChannelIdForChannelPost = 777;

public const string VideoMimeType = "video";
public const int MediaDcId = 1;
public const int QrCodeExpireSeconds = 30;
Expand Down
2 changes: 1 addition & 1 deletion source/src/MyTelegram.Domain.Shared/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace MyTelegram;

public partial record Peer(PeerType PeerType, long PeerId, long AccessHash = 0);
public partial record Peer(PeerType PeerType, long PeerId/*, long AccessHash = 0*/);
4 changes: 3 additions & 1 deletion source/src/MyTelegram.Domain.Shared/PrivacyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public enum PrivacyType
ProfilePhoto,
PhoneNumber,
AddedByPhone,
VoiceMessages
VoiceMessages,
About,
Birthday
}
6 changes: 1 addition & 5 deletions source/src/MyTelegram.Domain/Aggregates/AppCode/AppCodeId.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
namespace MyTelegram.Domain.Aggregates.AppCode;

[JsonConverter(typeof(SystemTextJsonSingleValueObjectConverter<AppCodeId>))]
public class AppCodeId : MyIdentity<AppCodeId>
public class AppCodeId(string value) : Identity<AppCodeId>(value)
{
public AppCodeId(string value) : base(value)
{
}

public static AppCodeId Create(string phoneNumber,
string phoneCodeHash)
{
Expand Down
Loading

0 comments on commit 6ac90c1

Please sign in to comment.