P
P
polupanov_ai2017-12-20 09:55:19
1C-Bitrix
polupanov_ai, 2017-12-20 09:55:19

How to post a message to a group using the API?

The question is relevant for people who have experience in working with api Bitrix and modules included in the editorial board Corp. portal.
Need to post a message to a social network group using api. After digging around, I realized that the messages in the group are the user's blog posts. It was possible to create a blog using CBlogPost::Add() , but I can’t figure out how to make this blog appear in the group’s message feed.
With the help of CBlogPost::GetList() it was possible to display a list of messages and there are messages that are already in the group feed and those that I created using CBlogPost::Add() .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2017-12-20
@polupanov_ai

To send a message to a live feed, you need an even more sophisticated method.
We connect the Social network module: To send a message to the feed, you need to have a post that will be sent to the feed, so first create a post:

$arFields = array(
 "TITLE" => "Заголовок записи",
 "DETAIL_TEXT" => "Тело сообщения",
 "BLOG_ID" => 1, //ID отправителя
 "AUTHOR_ID" => 1, //ID блога, в котором будет запись
 "DATE_PUBLISH" => '11.02.2014 09:08', // дада
 "PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH, // Читаем в API
 "ENABLE_TRACKBACK" => 'N',
 "ENABLE_COMMENTS" => 'Y'
);

On successful addition ($ID = CBlogPost::Add($arFields);) we get the blogPost post ID.
Then we need to send this post to the feed, for which we need a code snippet (replace accordingly):
$arEvent = array (
  'EVENT_ID'     => 'blog_post',
  '=LOG_DATE'    => 'now()',
  'TITLE_TEMPLATE' => '#USER_NAME# добавил(а) сообщение "#TITLE#" в блог',
  'TITLE'    => "Заголовок записи",
  'MESSAGE'  => "Текст записи",
  'TEXT_MESSAGE'  => "Текст записи",
  'MODULE_ID'     => 'blog',
  'CALLBACK_FUNC' => false,
  'SOURCE_ID'     => $ID,
  'ENABLE_COMMENTS'  => 'Y',
  'RATING_TYPE_ID'   => 'BLOG_POST',
  'RATING_ENTITY_ID' => $newID,
  'ENTITY_TYPE' => 'U',
  'ENTITY_ID'   => '1',
  'USER_ID'     => '1',
  'URL' => '/company/personal/user/1/blog/'.$ID.'/',
);

We create a record in the tape through: CSocNetLog::Add, we get eventID at the output (if successful)
If everything went well, then we set the rights to the post (in the example we send it to ALL G3 USERS)
// Выдает права
CSocNetLogRights::Add ( $eventID, array ("G3") );
// Отправляет уведомление о новом сообщении
CSocNetLog::SendEvent ( $eventID, 'SONET_NEW_EVENT' );

We rejoice =)
All parameters are obtained by means of GetList for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question