Bonjour voila, je suis en train de développer un chatbot sous messenger de facebook.
J'ai crée avec la fonction SetInterval(), une fonction qui me permet d'afficher une message toutes les 10 secondes.
J'ai aussi crée un fichier JSON qui contient les contenus à afficher :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 { "tarte":[ { "recette":"1", "ingredient1":"pomme", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"2", "ingredient1":"banane", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"3", "ingredient1":"fraise", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"4", "ingredient1":"poire", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"5", "ingredient1":"cerise", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"6", "ingredient1":"framboise", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"7", "ingredient1":"raisin", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"8", "ingredient1":"datte", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"9", "ingredient1":"kiwi", "ingredient2":"farine", "ingredient3":"sucre" }, { "recette":"10", "ingredient1":"ananas", "ingredient2":"farine", "ingredient3":"sucre" } ] }
J'aimerais juste que ma fonction en bas m'affiche un message avec un des différents élements ci dessus par 10 secondes voila comment j'ai coder :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 intervalMessage = setInterval(function () { let fs = require("fs"); let contents = fs.readFileSync("tarte.json"); let jsonContent = JSON.parse(contents); for (i=0;i<10;i++){ let recette = jsonContent.tarte[i].recette let ingredient1 = jsonContent.tarte[i].ingredient1 let ingredient2 = jsonContent.tarte[i].ingredient2 let ingredient3 = jsonContent.tarte[i].ingredient3 text= "Bonjour, voici la recette de la tarte numero :"+recette+" , elle est compose de "+ingredient1+", de "+ingredient2+" et de "+ingredient3+"." sendTextMessage(sender,text.substring(0, 200)) } }, 10000)
Mais ça me donne les 10 recettes d'un coup chaque 10 seconde.
Merci de m'eclairer sur mon erreur.
Partager