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; }
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); }
/// <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: - `type` with the value set to appropriate media type - and `payload` filled with the JSON you've got. For example, you can attach a video to message this way: 1. Get URL to upload. Execute following: ```shell curl -X POST \\ 'https://botapi.tamtam.chat/uploads?access_token=%access_token%&type=video' ``` As the result it will return URL for the next step. ```json { \"url\": \"http://vu.mycdn.me/upload.do…\" } ``` 2. Use this url to upload your binary: ```shell curl -i -X POST -H \"Content-Type: multipart/form-data\" -F \"data=@movie.mp4\" \"http://vu.mycdn.me/upload.do…\" ``` As the result it will return JSON you can attach to message: ```json { \"id\": 1234567890 } ``` 3. Send message with attach: ```json { \"text\": \"Message with video\", \"attachments\": [ { \"type\": \"video\", \"payload\": { \"id\": 1173574260020 } } ] } ``` **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't attach it. It means the last step will fail with `400` error. Try to send a message again until you'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)); }
/// <summary> /// Edit message /// Updated message should be sent as `NewMessageBody` in a request body. In case `attachments` field is `null`, 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)); }
/// <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); }
public EditMessageQuery(TamTamClient client, NewMessageBody newMessageBody, string messageId) : base(client, "/messages", newMessageBody, Method.PUT) { _messageId = new QueryParam <string>("message_id", messageId, this).Required(); }
/// <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); }