1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-04-04 22:14:37 +02:00

Дополнение словаря и перевод

This commit is contained in:
Anton 2024-07-19 22:48:39 +03:00
parent dd77b80f55
commit d09d8db5fa
6 changed files with 4600 additions and 4549 deletions

File diff suppressed because it is too large Load Diff

View File

@ -400,6 +400,9 @@ EndFunction
// Send media group
// Sends a set of files to a chat or channel. Media types: audio, document, photo, video
//
// Note
// Map: Key - File, Value - media type
//
// Parameters:
// Token - String - Bot token - token
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
@ -431,19 +434,18 @@ Function SendMediaGroup(Val Token
OPI_Tools.ReplaceSpecialCharacters(Text, Markup);
URL = "api.telegram.org/bot" + Token + "/sendMediaGroup";
FileStructure = New Structure;
Media = New Array;
Parameters = New Structure;
AddChatIdentifier(ChatID, Parameters);
FormMediaArray(FileMapping, Text, FileStructure, Media);
ConvertFilesToMedia(FileMapping, Text, Media);
OPI_Tools.AddField("parse_mode" , Markup , String_ , Parameters);
OPI_Tools.AddField("caption" , Text , String_ , Parameters);
OPI_Tools.AddField("media" , Media , String_ , Parameters);
OPI_Tools.AddField("reply_markup", Keyboard, "FileString", Parameters);
Response = OPI_Tools.PostMultipart(URL, Parameters, FileStructure, "mixed");
Response = OPI_Tools.PostMultipart(URL, Parameters, FileMapping, "mixed");
Return Response;
@ -1060,10 +1062,15 @@ Function SendFile(Val Token
Method = "";
DetermineSendMethod(View, Method, Extension);
ConvertFileData(File, Extension, View);
OPI_Tools.ReplaceSpecialCharacters(Text, Markup);
FileName = ?(ValueIsFilled(FileName), View + "|" + FileName, View + Extension);
If Not ValueIsFilled(FileName) Then
FileName = ConvertFileData(File, View, "");
Else
OPI_TypeConversion.GetBinaryData(File);
EndIf;
FileName = View + "|" + FileName;
Parameters = New Structure;
OPI_Tools.AddField("parse_mode" , Markup , "String" , Parameters);
@ -1102,8 +1109,7 @@ Function ForumTopicManagement(Val Token
Else
Method = "/createForumTopic";
EndIf;
OPI_Tools.RemoveEmptyCollectionFields(Parameters);
Response = OPI_Tools.Get("api.telegram.org/bot" + Token + Method, Parameters);
Return Response;
@ -1205,9 +1211,7 @@ Function CreateLongKeyboard(Val ButtonArray)
EndFunction
Procedure FormMediaArray(Val FileMapping, Val Text, FileStructure, Media)
Counter = 0;
Procedure ConvertFilesToMedia(FileMapping, Text, Media)
OPI_TypeConversion.GetCollection(FileMapping);
OPI_TypeConversion.GetLine(Text);
@ -1216,44 +1220,36 @@ Procedure FormMediaArray(Val FileMapping, Val Text, FileStructure, Media)
Raise("Failed to Retrieve Information from JSON media!");
Return;
EndIf;
For Each CurrentFile In FileMapping Do
If Not TypeOf(CurrentFile.Key) = Type("BinaryData") Then
Binary = CurrentFile.Key;
OPI_TypeConversion.GetBinaryData(Binary);
ThisFile = New File(CurrentFile.Key);
MediaName = CurrentFile.Value
+ String(Counter)
+ ?(CurrentFile.Value = "document", ThisFile.Extension, "");
FullMediaName = StrReplace(MediaName, ".", "___");
Else
Binary = CurrentFile.Key;
MediaName = CurrentFile.Value + String(Counter);
FullMediaName = MediaName;
EndIf;
FileStructure.Insert(FullMediaName, Binary);
MediaStructure = New Structure;
MediaStructure.Insert("type" , CurrentFile.Value);
MediaStructure.Insert("media", "attach://" + MediaName);
If Counter = 0 Then
MediaStructure.Insert("caption", Text);
EndIf;
Media.Add(MediaStructure);
Counter = Counter + 1;
EndDo;
TempMap = New Map;
Counter = 0;
For Each CurrentFile In FileMapping Do
CurrentData = CurrentFile.Key;
TypeOfMedia = CurrentFile.Value;
Extension = "";
MediaName = ConvertFileData(CurrentData, TypeOfMedia, Counter);
TempMap.Insert(MediaName + "|" + MediaName, CurrentData);
MediaStructure = New Structure;
MediaStructure.Insert("type" , TypeOfMedia);
MediaStructure.Insert("media", "attach://" + MediaName);
If Counter = 0 Then
MediaStructure.Insert("caption", Text);
EndIf;
Media.Add(MediaStructure);
Counter = Counter + 1;
EndDo;
Media = OPI_Tools.JSONString(Media);
FileMapping = TempMap;
EndProcedure
@ -1294,18 +1290,25 @@ Procedure DetermineSendMethod(Val View, Method, Extension)
EndProcedure
Procedure ConvertFileData(File, Extension, View)
Function ConvertFileData(File, View, Counter)
If Not TypeOf(File) = Type("BinaryData") Then
FileName = "";
If TypeOf(File) = Type("String") And View = "document" Then
CurrentFile = New File(File);
Extension = ?(View = "document", CurrentFile.Extension, Extension);
OPI_TypeConversion.GetBinaryData(File);
FileName = CurrentFile.Name;
EndIf;
Extension = StrReplace(Extension, ".", "___");
EndProcedure
If Not ValueIsFilled(FileName) Then
FileName = View + String(Counter);
EndIf;
OPI_TypeConversion.GetBinaryData(File);
Return FileName;
EndFunction
#EndRegion

View File

@ -1,21 +1,21 @@
<package-def>
<module name="OPI_Cryptography" file="tools/Modules/internal/Modules/OPI_Cryptography.os"/>
<module name="OPI_Tools" file="tools/Modules/internal/Modules/OPI_Tools.os"/>
<module name="OPI_GoogleDrive" file="core/Modules/OPI_GoogleDrive.os"/>
<module name="OPI_Twitter" file="core/Modules/OPI_Twitter.os"/>
<module name="OPI_YandexID" file="core/Modules/OPI_YandexID.os"/>
<module name="OPI_Dropbox" file="core/Modules/OPI_Dropbox.os"/>
<module name="OPI_GoogleWorkspace" file="core/Modules/OPI_GoogleWorkspace.os"/>
<module name="OPI_Bitrix24" file="core/Modules/OPI_Bitrix24.os"/>
<module name="OPI_Viber" file="core/Modules/OPI_Viber.os"/>
<module name="OPI_GoogleCalendar" file="core/Modules/OPI_GoogleCalendar.os"/>
<module name="OPI_Telegram" file="core/Modules/OPI_Telegram.os"/>
<module name="OPI_Airtable" file="core/Modules/OPI_Airtable.os"/>
<module name="OPI_Slack" file="core/Modules/OPI_Slack.os"/>
<module name="OPI_Notion" file="core/Modules/OPI_Notion.os"/>
<module name="OPI_Bitrix24" file="core/Modules/OPI_Bitrix24.os"/>
<module name="OPI_Dropbox" file="core/Modules/OPI_Dropbox.os"/>
<module name="OPI_GoogleCalendar" file="core/Modules/OPI_GoogleCalendar.os"/>
<module name="OPI_GoogleDrive" file="core/Modules/OPI_GoogleDrive.os"/>
<module name="OPI_GoogleSheets" file="core/Modules/OPI_GoogleSheets.os"/>
<module name="OPI_YandexDisk" file="core/Modules/OPI_YandexDisk.os"/>
<module name="OPI_TypeConversion" file="tools/Modules/OPI_TypeConversion.os"/>
<module name="OPI_GoogleWorkspace" file="core/Modules/OPI_GoogleWorkspace.os"/>
<module name="OPI_Notion" file="core/Modules/OPI_Notion.os"/>
<module name="OPI_Slack" file="core/Modules/OPI_Slack.os"/>
<module name="OPI_Telegram" file="core/Modules/OPI_Telegram.os"/>
<module name="OPI_Twitter" file="core/Modules/OPI_Twitter.os"/>
<module name="OPI_Viber" file="core/Modules/OPI_Viber.os"/>
<module name="OPI_VK" file="core/Modules/OPI_VK.os"/>
<module name="OPI_YandexDisk" file="core/Modules/OPI_YandexDisk.os"/>
<module name="OPI_YandexID" file="core/Modules/OPI_YandexID.os"/>
<module name="OPI_Tools" file="tools/Modules/internal/Modules/OPI_Tools.os"/>
<module name="OPI_Cryptography" file="tools/Modules/internal/Modules/OPI_Cryptography.os"/>
<module name="OPI_TestDataRetrieval" file="tools/Modules/OPI_TestDataRetrieval.os"/>
<module name="OPI_TypeConversion" file="tools/Modules/OPI_TypeConversion.os"/>
</package-def>

View File

@ -185,6 +185,7 @@ Procedure TelegramAPI_SendMediaGroup() Export
OPI_TestDataRetrieval.ParameterToCollection("String" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Video" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Document" , TestParameters);
Telegram_SendMediaGroup(TestParameters);
@ -4143,10 +4144,27 @@ Procedure Telegram_SendMediaGroup(FunctionParameters)
OPI_TestDataRetrieval.WriteLog(Result, "SendMediaGroup", "Telegram");
Check_TelegramMediaGroup(Result);
Check_TelegramMediaGroup(Result);
DocumentURL = FunctionParameters["Document"];
DocumentPath = GetTempFileName("docx");
ChannelID = FunctionParameters["Telegram_ChannelID"];
CopyFile(DocumentURL, DocumentPath);
MediaGroup = New Map;
MediaGroup.Insert(DocumentURL , "document");
MediaGroup.Insert(DocumentPath, "document");
Result = OPI_Telegram.SendMediaGroup(Token, ChannelID, Text, MediaGroup);
OPI_TestDataRetrieval.WriteLog(Result, "SendMediaGroup (docs)", "Telegram");
Check_TelegramMediaGroup(Result);
DeleteFiles(VideoPath);
DeleteFiles(ImagePath);
DeleteFiles(DocumentPath);
OPI_Tools.Pause(5);

View File

@ -400,6 +400,9 @@ EndFunction
// Send media group
// Sends a set of files to a chat or channel. Media types: audio, document, photo, video
//
// Note
// Map: Key - File, Value - media type
//
// Parameters:
// Token - String - Bot token - token
// ChatID - String, Number - Target chat ID or ChatID*TopicID - chat
@ -431,19 +434,18 @@ Function SendMediaGroup(Val Token
OPI_Tools.ReplaceSpecialCharacters(Text, Markup);
URL = "api.telegram.org/bot" + Token + "/sendMediaGroup";
FileStructure = New Structure;
Media = New Array;
Parameters = New Structure;
AddChatIdentifier(ChatID, Parameters);
FormMediaArray(FileMapping, Text, FileStructure, Media);
ConvertFilesToMedia(FileMapping, Text, Media);
OPI_Tools.AddField("parse_mode" , Markup , String_ , Parameters);
OPI_Tools.AddField("caption" , Text , String_ , Parameters);
OPI_Tools.AddField("media" , Media , String_ , Parameters);
OPI_Tools.AddField("reply_markup", Keyboard, "FileString", Parameters);
Response = OPI_Tools.PostMultipart(URL, Parameters, FileStructure, "mixed");
Response = OPI_Tools.PostMultipart(URL, Parameters, FileMapping, "mixed");
Return Response;
@ -1060,10 +1062,15 @@ Function SendFile(Val Token
Method = "";
DetermineSendMethod(View, Method, Extension);
ConvertFileData(File, Extension, View);
OPI_Tools.ReplaceSpecialCharacters(Text, Markup);
FileName = ?(ValueIsFilled(FileName), View + "|" + FileName, View + Extension);
If Not ValueIsFilled(FileName) Then
FileName = ConvertFileData(File, View, "");
Else
OPI_TypeConversion.GetBinaryData(File);
EndIf;
FileName = View + "|" + FileName;
Parameters = New Structure;
OPI_Tools.AddField("parse_mode" , Markup , "String" , Parameters);
@ -1102,8 +1109,7 @@ Function ForumTopicManagement(Val Token
Else
Method = "/createForumTopic";
EndIf;
OPI_Tools.RemoveEmptyCollectionFields(Parameters);
Response = OPI_Tools.Get("api.telegram.org/bot" + Token + Method, Parameters);
Return Response;
@ -1205,9 +1211,7 @@ Function CreateLongKeyboard(Val ButtonArray)
EndFunction
Procedure FormMediaArray(Val FileMapping, Val Text, FileStructure, Media)
Counter = 0;
Procedure ConvertFilesToMedia(FileMapping, Text, Media)
OPI_TypeConversion.GetCollection(FileMapping);
OPI_TypeConversion.GetLine(Text);
@ -1216,44 +1220,36 @@ Procedure FormMediaArray(Val FileMapping, Val Text, FileStructure, Media)
// !OInt RaiseException("Failed to get information from json media!");
Return;
EndIf;
For Each CurrentFile In FileMapping Do
If Not TypeOf(CurrentFile.Key) = Type("BinaryData") Then
Binary = CurrentFile.Key;
OPI_TypeConversion.GetBinaryData(Binary);
ThisFile = New File(CurrentFile.Key);
MediaName = CurrentFile.Value
+ String(Counter)
+ ?(CurrentFile.Value = "document", ThisFile.Extension, "");
FullMediaName = StrReplace(MediaName, ".", "___");
Else
Binary = CurrentFile.Key;
MediaName = CurrentFile.Value + String(Counter);
FullMediaName = MediaName;
EndIf;
FileStructure.Insert(FullMediaName, Binary);
MediaStructure = New Structure;
MediaStructure.Insert("type" , CurrentFile.Value);
MediaStructure.Insert("media", "attach://" + MediaName);
If Counter = 0 Then
MediaStructure.Insert("caption", Text);
EndIf;
Media.Add(MediaStructure);
Counter = Counter + 1;
EndDo;
TempMap = New Map;
Counter = 0;
For Each CurrentFile In FileMapping Do
CurrentData = CurrentFile.Key;
TypeOfMedia = CurrentFile.Value;
Extension = "";
MediaName = ConvertFileData(CurrentData, TypeOfMedia, Counter);
TempMap.Insert(MediaName + "|" + MediaName, CurrentData);
MediaStructure = New Structure;
MediaStructure.Insert("type" , TypeOfMedia);
MediaStructure.Insert("media", "attach://" + MediaName);
If Counter = 0 Then
MediaStructure.Insert("caption", Text);
EndIf;
Media.Add(MediaStructure);
Counter = Counter + 1;
EndDo;
Media = OPI_Tools.JSONString(Media);
FileMapping = TempMap;
EndProcedure
@ -1294,18 +1290,25 @@ Procedure DetermineSendMethod(Val View, Method, Extension)
EndProcedure
Procedure ConvertFileData(File, Extension, View)
Function ConvertFileData(File, View, Counter)
If Not TypeOf(File) = Type("BinaryData") Then
FileName = "";
If TypeOf(File) = Type("String") And View = "document" Then
CurrentFile = New File(File);
Extension = ?(View = "document", CurrentFile.Extension, Extension);
OPI_TypeConversion.GetBinaryData(File);
FileName = CurrentFile.Name;
EndIf;
Extension = StrReplace(Extension, ".", "___");
EndProcedure
If Not ValueIsFilled(FileName) Then
FileName = View + String(Counter);
EndIf;
OPI_TypeConversion.GetBinaryData(File);
Return FileName;
EndFunction
#EndRegion

View File

@ -185,6 +185,7 @@ Procedure TelegramAPI_SendMediaGroup() Export
OPI_TestDataRetrieval.ParameterToCollection("String" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Picture" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Video" , TestParameters);
OPI_TestDataRetrieval.ParameterToCollection("Document" , TestParameters);
Telegram_SendMediaGroup(TestParameters);
@ -4143,10 +4144,27 @@ Procedure Telegram_SendMediaGroup(FunctionParameters)
// !OInt OPI_TestDataRetrieval.WriteLog(Result, "SendMediaGroup", "Telegram");
Check_TelegramMediaGroup(Result);
Check_TelegramMediaGroup(Result);
DocumentURL = FunctionParameters["Document"];
DocumentPath = GetTempFileName("docx");
ChannelID = FunctionParameters["Telegram_ChannelID"];
FileCopy(DocumentURL, DocumentPath);
MediaGroup = New Map;
MediaGroup.Insert(DocumentURL , "document");
MediaGroup.Insert(DocumentPath, "document");
Result = OPI_Telegram.SendMediaGroup(Token, ChannelID, Text, MediaGroup);
// !OInt OPI_TestDataRetrieval.WriteLog(Result, "SendMediaGroup (docs)", "Telegram");
Check_TelegramMediaGroup(Result);
DeleteFiles(VideoPath);
DeleteFiles(ImagePath);
DeleteFiles(DocumentPath);
OPI_Tools.Pause(5);