1# Publishing a Text Notification
2
3You can publish text notifications to send SMS messages, alert messages, and more. There are two types of text notifications: normal text and multi-line text.
4
5**Table 1** Basic notification content types
6
7| Type                            | Description         |
8| ------------------------------- | ------------- |
9| NOTIFICATION_CONTENT_BASIC_TEXT | Normal text notification.|
10| NOTIFICATION_CONTENT_MULTILINE  | Multi-line text notification.|
11
12## Available APIs
13
14The following table describes the APIs for notification publishing. You specify the notification information – content, ID, slot type, and publish time – by setting the [NotificationRequest](../reference/apis-notification-kit/js-apis-inner-notification-notificationRequest.md#notificationrequest) parameter in the APIs.
15
16| Name| Description|
17| -------- | -------- |
18| publish(request: NotificationRequest, callback: AsyncCallback<void>): void | Publishes a notification.                |
19| cancel(id: number, label: string, callback: AsyncCallback<void>): void | Cancels a notification.          |
20| cancelAll(callback: AsyncCallback<void>): void | Cancels all notifications published by the application.|
21
22
23## How to Develop
24
251. Import the module.
26
27   ```ts
28   import { notificationManager } from '@kit.NotificationKit';
29   import { BusinessError } from '@kit.BasicServicesKit';
30   import { hilog } from '@kit.PerformanceAnalysisKit';
31
32   const TAG: string = '[PublishOperation]';
33   const DOMAIN_NUMBER: number = 0xFF00;
34   ```
35
362. Create a **NotificationRequest** object and publish a progress notification.
37   - A normal text notification consists of the **title**, **text**, and **additionalText** parameters, of which **title** and **text** are mandatory. The value of these parameters contains less than 200 bytes. Excess content will be truncated.
38
39      ```ts
40      let notificationRequest: notificationManager.NotificationRequest = {
41        id: 1,
42        content: {
43          notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // Basic notification
44          normal: {
45            title: 'test_title',
46            text: 'test_text',
47            additionalText: 'test_additionalText',
48          }
49        }
50      };
51      notificationManager.publish(notificationRequest, (err: BusinessError) => {
52        if (err) {
53          hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
54          return;
55        }
56        hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
57      });
58      ```
59
60
61   - In addition to the parameters in the normal text notification, the multi-line text notification provides the **lines**, **briefText**, and **longTitle** parameters. The value of these parameters contains less than 200 bytes. Excess content will be truncated. By default, a multi-line notification looks in the same way as a normal text notification. When expanded, the notification displays the title and content specified in **longTitle** and **lines**, respectively.
62
63      ```ts
64      let notificationRequest: notificationManager.NotificationRequest = {
65        id: 3,
66        content: {
67          notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // Multi-line text notification
68          multiLine: {
69            title: 'test_title',
70            text: 'test_text',
71            briefText: 'test_briefText',
72            longTitle: 'test_longTitle',
73            lines: ['line_01', 'line_02', 'line_03', 'line_04'],
74          }
75        }
76      };
77      // Publish the notification.
78      notificationManager.publish(notificationRequest, (err: BusinessError) => {
79        if (err) {
80          hilog.error(DOMAIN_NUMBER, TAG, `Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
81          return;
82        }
83        hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.');
84      });
85      ```
863. Delete the notification.
87
88   ```ts
89    notificationManager.cancel(1, (err: BusinessError) => {
90      if (err) {
91        hilog.error(DOMAIN_NUMBER, TAG, `Failed to cancel notification. Code is ${err.code}, message is ${err.message}`);
92        return;
93      }
94      hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in cancel notification.');
95    });
96   ```
97