Esempio n. 1
0
        private void Cli_OnMessageUpdate(object sender, MessageCreatedUpdate e)
        {
            Message message = e.Message;

            Console.WriteLine($"Received message. {message.Body.Text}");


            CallbackButton button = new CallbackButton();

            button.Payload = "/call";
            button.Text    = "Кнопка";
            button.Intent  = Intent.Positive;

            Collection <Button> col = new Collection <Button>();

            col.Add(button);

            Payload9 keyb = new Payload9();

            keyb.Buttons.Add(col);

            InlineKeyboardAttachmentRequest kb = new InlineKeyboardAttachmentRequest();

            kb.Payload = keyb;

            NewMessageBody b = new NewMessageBody();

            b.Text        = $"Echo: {message.Body.Text}";
            b.Attachments = new Collection <AttachmentRequest>();

            b.Attachments.Add(kb);


            var r = cli.SendMessageAsync(b, message.Recipient.User_id, message.Recipient.Chat_id).Result;
        }
Esempio n. 2
0
 public SendMessageQuery(TamTamClient client, NewMessageBody newMessageBody)
     : base(client, "/messages", newMessageBody, Method.POST)
 {
     _userId             = new QueryParam <long>("user_id", this);
     _chatId             = new QueryParam <long>("chat_id", this);
     _disableLinkPreview = new QueryParam <bool>("disable_link_preview", this);
 }
Esempio n. 3
0
        /// <summary>
        /// Sends a message to a chat. As a result for this method new message identifier returns. ### Attaching media Attaching media to messages is a three-step process.  At first step, you should [obtain a URL to upload](#operation/getUploadUrl) your media files.  At the second, you should upload binary of appropriate format to URL you obtained at the previous step. See [upload](https://dev.tamtam.chat/#operation/getUploadUrl) section for details.  Finally, if the upload process was successful, you will receive JSON-object in a response body.  Use this object to create attachment. Construct an object with two properties:  - &#x60;type&#x60; with the value set to appropriate media type  - and &#x60;payload&#x60; filled with the JSON you&#39;ve got.   For example, you can attach a video to message this way:  1. Get URL to upload. Execute following: &#x60;&#x60;&#x60;shell curl -X POST \\   &#39;https://botapi.tamtam.chat/uploads?access_token&#x3D;%access_token%&amp;type&#x3D;video&#39; &#x60;&#x60;&#x60; As the result it will return URL for the next step. &#x60;&#x60;&#x60;json {     \&quot;url\&quot;: \&quot;http://vu.mycdn.me/upload.do…\&quot; } &#x60;&#x60;&#x60;   2. Use this url to upload your binary:  &#x60;&#x60;&#x60;shell curl -i -X POST      -H \&quot;Content-Type: multipart/form-data\&quot;      -F \&quot;data&#x3D;@movie.mp4\&quot; \&quot;http://vu.mycdn.me/upload.do…\&quot; &#x60;&#x60;&#x60; As the result it will return JSON you can attach to message: &#x60;&#x60;&#x60;json {     \&quot;id\&quot;: 1234567890 } &#x60;&#x60;&#x60; 3. Send message with attach: &#x60;&#x60;&#x60;json {  \&quot;text\&quot;: \&quot;Message with video\&quot;,  \&quot;attachments\&quot;: [   {    \&quot;type\&quot;: \&quot;video\&quot;,    \&quot;payload\&quot;: {        \&quot;id\&quot;: 1173574260020    }   }  ] } &#x60;&#x60;&#x60;  **Important notice**:  It may take time for the server to process your file (audio/video or any binary). While a file is not processed you can&#39;t attach it. It means the last step will fail with &#x60;400&#x60; error. Try to send a message again until you&#39;ll get a successful result.
        /// </summary>
        /// <param name="newMessageBody">(required)</param>
        /// <returns>SendMessageResult</returns>
        public SendMessageQuery SendMessage(NewMessageBody newMessageBody)
        {
            if (newMessageBody == null)
            {
                throw new RequiredParameterMissingException("Missing the required request body when calling sendMessage");
            }

            return(new SendMessageQuery(_client, newMessageBody));
        }
Esempio n. 4
0
        /// <summary>
        /// Edit message
        /// Updated message should be sent as &#x60;NewMessageBody&#x60; in a request body. In case &#x60;attachments&#x60; field is &#x60;null&#x60;, the current message attachments won’t be changed. In case of sending an empty list in this field, all attachments will be deleted.
        /// </summary>
        /// <param name="newMessageBody">(required)</param>
        /// <param name="messageId">Editing message identifier (required)</param>
        /// <returns>SimpleQueryResult</returns>
        public EditMessageQuery EditMessage(NewMessageBody newMessageBody, String messageId)
        {
            if (messageId == null)
            {
                throw new RequiredParameterMissingException("Missing the required parameter 'message_id' when calling editMessage");
            }

            if (newMessageBody == null)
            {
                throw new RequiredParameterMissingException("Missing the required request body when calling editMessage");
            }

            return(new EditMessageQuery(_client, newMessageBody, messageId));
        }
Esempio n. 5
0
        /// <summary>
        /// Send message.
        /// </summary>
        public async Task <IApiResponse <SendMessageResult> > SendMessageAsync(NewMessageBody message, long?userId = null, long?chatId = null, CancellationToken cancellationToken = default)
        {
            var relativeRequireUrl = $"messages?access_token={_accessToken}";

            if (userId.HasValue)
            {
                relativeRequireUrl += $"&user_id={userId.Value}";
            }
            if (chatId.HasValue)
            {
                relativeRequireUrl += $"&chat_id={chatId.Value}";
            }
            IApiResponse <SendMessageResult> result = null;

            result = await SenderApi.PostAsync <SendMessageResult>(_connectorClient, GetApiUri(relativeRequireUrl), message, cancellationToken);

            return(result);
        }
Esempio n. 6
0
 public EditMessageQuery(TamTamClient client, NewMessageBody newMessageBody, string messageId)
     : base(client, "/messages", newMessageBody, Method.PUT)
 {
     _messageId = new QueryParam <string>("message_id", messageId, this).Required();
 }
Esempio n. 7
0
        /// <summary>
        /// Edit message.
        /// </summary>
        public async Task <IApiResponse <SimpleQueryResult> > EditMessageAsync(string messageId, NewMessageBody message, CancellationToken cancellationToken = default)
        {
            IApiResponse <SimpleQueryResult> result = null;

            result = await SenderApi.PutAsync <SimpleQueryResult>(_connectorClient, GetApiUri($"messages?access_token={_accessToken}&message_id={messageId}"), message, cancellationToken);

            return(result);
        }