public bool SendE2ETextMessage(ThreemaE2ETextMessage threemaE2ETextMessage) { try { try { _log.LogDebug("ThreemaController.SendE2ETextMessage: ModelState {0}, ThreemaE2ETextMessage {1}", ModelState.IsValid, threemaE2ETextMessage.ToString()); } catch (Exception ex) { _log.LogError("ThreemaController.SendE2ETextMessage 1 " + ex.Message); } string myPrivateKey = this._configuration["Threema:PrivateKey"]; string myThreemaId = this._configuration["Threema:ThreemaId"]; string mySecret = this._configuration["Threema:Secret"]; APIConnector apiConnector = new APIConnector(myThreemaId, mySecret, null); string text = DataUtils.Utf8Endcode(threemaE2ETextMessage.Text.Trim()); Key privateKey = Key.DecodeKey(myPrivateKey); E2EHelper e2EHelper = new E2EHelper(apiConnector, privateKey.key); String messageId = e2EHelper.SendTextMessage(threemaE2ETextMessage.To, text); _log.LogDebug("ThreemaController.SendE2ETextMessage: messege sendet to {0}", threemaE2ETextMessage.To); return(true); } catch (Exception ex) { _log.LogError("ThreemaController.SendE2ETextMessage 2 " + ex.Message); return(false); } }
/// <summary> /// Wrapper to send image message E2E <see cref="Threema.MsgApi.E2EHelper.SendImageMessage"/> /// </summary> /// <param name="to">Recipient id</param> /// <param name="from">Sender id</param> /// <param name="secret">Sender sercret</param> /// <param name="privateKey">Sender private key</param> /// <param name="imageFilePath">File path to image</param> /// <param name="apiUrl">Optional api url</param> /// <returns>Message id</returns> public string SendImageMessage(string to, string from, string secret, string privateKey, string imageFilePath, string apiUrl = APIConnector.DEFAULTAPIURL) { byte[] privateKeyBytes = GetKey(privateKey, Key.KeyType.PRIVATE); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret, apiUrl), privateKeyBytes); return(e2EHelper.SendImageMessage(to, imageFilePath)); }
/// <summary> /// Wrapper to send text message E2E <see cref="Threema.MsgApi.E2EHelper.SendTextMessage"/> /// </summary> /// <param name="to">Recipient id</param> /// <param name="from">Sender id</param> /// <param name="secret">Sender sercret</param> /// <param name="privateKey">Sender private key</param> /// <param name="text">Text message</param> /// <param name="apiUrl">Optional api url</param> /// <returns>Message id</returns> public string SendTextMessage(string to, string from, string secret, string privateKey, string text, string apiUrl = APIConnector.DEFAULTAPIURL) { byte[] privateKeyBytes = GetKey(privateKey, Key.KeyType.PRIVATE); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret, apiUrl), privateKeyBytes); return(e2EHelper.SendTextMessage(to, DataUtils.Utf8Endcode(text))); }
/// <summary> /// Wrapper to send file message E2E <see cref="Threema.MsgApi.E2EHelper.SendFileMessage"/> /// </summary> /// <param name="to">Recipient id</param> /// <param name="from">Sender id</param> /// <param name="secret">Sender sercret</param> /// <param name="privateKey">Sender private key</param> /// <param name="file">File path to file</param> /// <param name="thumbnail">File path to thumbnail</param> /// <param name="apiUrl">Optional api url</param> /// <returns>Message id</returns> public string SendFileMessage(string to, string from, string secret, string privateKey, string file, string thumbnail = null, string apiUrl = APIConnector.DEFAULTAPIURL) { byte[] privateKeyBytes = GetKey(privateKey, Key.KeyType.PRIVATE); FileInfo fileInfo = file != null ? new FileInfo(file) : null; FileInfo thumbnailInfo = thumbnail != null ? new FileInfo(thumbnail) : null; E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret, apiUrl), privateKeyBytes); return(e2EHelper.SendFileMessage(to, fileInfo, thumbnailInfo)); }
protected override void Execute() { string to = this.toField.Value; string from = this.fromField.Value; string secret = this.secretField.Value; byte[] privateKey = this.privateKeyField.GetValue(); string imageFilePath = this.imageFilePath.GetValue(); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret), privateKey); string messageId = e2EHelper.SendImageMessage(to, imageFilePath); System.Console.WriteLine("MessageId: " + messageId); }
protected override void Execute() { string to = this.threemaId.Value; string from = this.fromField.Value; string secret = this.secretField.Value; byte[] privateKey = this.privateKeyField.GetValue(); FileInfo file = this.fileField.GetValue(); FileInfo thumbnail = this.thumbnailField.GetValue(); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret), privateKey); string messageId = e2EHelper.SendFileMessage(to, file, thumbnail); System.Console.WriteLine("MessageId: " + messageId); }
protected override void Execute() { string to = this.threemaId.Value; string from = this.fromField.Value; string secret = this.secretField.Value; byte[] privateKey = this.privateKeyField.GetValue(); //string text = ReadStream(System.Console.In).Trim(); string text = DataUtils.Utf8Endcode(System.Console.ReadLine().Trim()); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret), privateKey); String messageId = e2EHelper.SendTextMessage(to, text); System.Console.WriteLine("MessageId: " + messageId); }
/// <summary> /// Wrapper to receive message and download files <see cref="Threema.MsgApi.Helpers.E2EHelper.ReceiveMessage"/> /// </summary> /// <param name="id">Sender id</param> /// <param name="from">From id</param> /// <param name="secret">From secret</param> /// <param name="privateKey">From private key</param> /// <param name="messageId">Message id</param> /// <param name="nonce">Nonce as hex-string</param> /// <param name="box">Box message as hex-string</param> /// <param name="outputFolder">Optional path to output folder</param> /// <param name="apiUrl">Optional api url</param> /// <returns>Array with message-type, message-id and message</returns> public ArrayList ReceiveMessage(string id, string from, string secret, string privateKey, string messageId, string nonce, string box, string outputFolder = null, string apiUrl = APIConnector.DEFAULTAPIURL) { byte[] privateKeyBytes = GetKey(privateKey, Key.KeyType.PRIVATE); byte[] nonceBytes = DataUtils.HexStringToByteArray(nonce); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret, apiUrl), privateKeyBytes); byte[] boxBytes = DataUtils.HexStringToByteArray(box); ReceiveMessageResult res = e2EHelper.ReceiveMessage(id, messageId, boxBytes, nonceBytes, outputFolder); ArrayList result = new ArrayList(); result.Add(res.Message.GetTypeCode().ToString()); result.Add(res.MessageId); result.Add(res.Message.ToString()); return(result); }
protected override void Execute() { string id = this.threemaId.Value; string from = this.fromField.Value; string secret = this.secretField.Value; byte[] privateKey = this.privateKeyField.GetValue(); byte[] nonce = this.nonceField.GetValue(); string messageId = this.messageIdField.Value; string outputFolder = this.outputFolderField.GetValue(); E2EHelper e2EHelper = new E2EHelper(this.CreateConnector(from, secret), privateKey); byte[] box = DataUtils.HexStringToByteArray(System.Console.ReadLine().Trim()); ReceiveMessageResult res = e2EHelper.ReceiveMessage(id, messageId, box, nonce, outputFolder); System.Console.WriteLine(res.Message.ToString()); res.Files.ForEach(f => { System.Console.WriteLine(f.FullName); }); }